Bulk insert with SQLAlchemy ORM in Python Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will see how to insert or add bulk data using SQLAlchemy in Python. SQLAlchemy is among one of the best libraries to establish communication between python and databases. We have used the PostgreSQL database for this article. Create a database for demonstration: CREATE DATABASE TEST; Create a connection to the Postgres database Python3 from sqlalchemy import create_engine engine = create_engine("postgresql+psycopg2:/\ /postgres:root@localhost:5432/test",echo=True) Create a Table Student Python3 from sqlalchemy import Table, Column, Integer, String, MetaData meta = MetaData() students = Table('students', meta, Column('id', Integer, primary_key = True), Column('name', String), Column('lastname', String), ) meta.create_all(engine) Output: Now, login to the database "test" and check the table name "students" created. BULK INSERT Bulk insert with SQLAlchemy ORM In PostgreSQL, we can add bulk data into tables using COPY COMMAND, IMPORT, and through generate_series. generate_series Python3 engine.execute("INSERT INTO students (id, name, lastname)\ SELECT gt,'Scott Derrickson','Derrickson'\ FROM generate_series(4,10) as gt") Output: Copy command Python3 engine.execute("COPY students(id,name,lastname)\ FROM 'PATH' DELIMITER ',' CSV HEADER") Output: Comment More infoAdvertise with us Next Article Bulk insert with SQLAlchemy ORM in Python N nidhixpcd Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2022 Practice Tags : python Similar Reads SQLalchemy Bulk insert with one to one relation When working with databases in Python, SQLAlchemy is a popular and powerful library that provides a high-level interface for interacting with relational databases. It offers an Object-Relational Mapping (ORM) layer that allows developers to work with database tables as Python objects. In this articl 5 min read Python SQLAlchemy - func.count with filter In this article, we are going to see how to perform filter operation with count function in SQLAlchemy against a PostgreSQL database in python Count with filter operations is performed in different methods using different functions. Such kinds of mathematical operations are database-dependent. In Po 3 min read How to Install SQLAlchemy in Python on Linux? SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that is used as flexible database access using SQL. In this article, we will look into the process of installing SQLAlchemy on a windows machine. Pre-requisites: The only thing that you need for installing Numpy on Windows are: Python 2 min read How to Install sqlalchemy in Python on MacOS? In this article, we will learn how to install SQLAlchemy in Python on MacOS. SQLAlchemy is the Python SQL toolkit and Object Relational Mapper that gives application developers the full power and flexibility of SQL Installation:Method 1: Using pip to install SQLAlchemy Follow the below steps to inst 2 min read Connecting PostgreSQL with SQLAlchemy in Python In this article, we will discuss how to connect PostgreSQL with SQLAlchemy in Python. In order to connect with any Database management system, it is essential to create an engine object, that serves as a central source of connection by providing a connection pool that manages the database connection 3 min read Like