Skip to main content

Fast db insert with postgresql binary copy

Project description

Use pgcopy for fast data loading into PostgreSQL with binary copy.


  • Support for many data types

  • Support for multi-dimensional array types

  • Support for schema and schema search path

  • Support for mixed-case table and column names

  • Transparent string encoding

  • Utility for replacing entire table


from datetime import datetime
from pgcopy import CopyManager
import psycopg2
cols = ('id', 'timestamp', 'location', 'temperature')
now =
records = [
        (0, now, 'Jerusalem', 72.2),
        (1, now, 'New York', 75.6),
        (2, now, 'Moscow', 54.3),
conn = psycopg2.connect(database='weather_db')
mgr = CopyManager(conn, 'measurements_table', cols)

# don't forget to commit!

Supported datatypes

pgcopy supports the following PostgreSQL scalar types:

  • bool

  • smallint

  • integer

  • bigint

  • real

  • double precision

  • char

  • varchar

  • text

  • bytea

  • enum types

  • date

  • time

  • timestamp

  • timestamp with time zone

  • numeric

  • json

  • jsonb

  • uuid

  • arrays

  • vector


Read the docs.

See Also

cpgcopy, a Cython implementation, about twice as fast.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgcopy-1.6.0.tar.gz (18.6 kB view hashes)

Uploaded Source

Built Distribution

pgcopy-1.6.0-py2.py3-none-any.whl (13.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page