Skip to main content

Fast db insert with postgresql binary copy

Project description

https://travis-ci.org/altaurog/pgcopy.svg?branch=master https://coveralls.io/repos/github/altaurog/pgcopy/badge.svg?branch=master https://img.shields.io/pypi/l/pgcopy.svg https://img.shields.io/pypi/wheel/pgcopy.svg https://img.shields.io/pypi/pyversions/pgcopy.svg

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

Features

  • Support for many data types
  • Support for multi-dimensional array types
  • Support for schema and schema search path
  • Transparent string encoding
  • Utility for replacing entire table

Quickstart

from datetime import datetime
from pgcopy import CopyManager
import psycopg2
cols = ('id', 'timestamp', 'location', 'temperature')
now = datetime.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)
mgr.copy(records)

# don't forget to commit!
conn.commit()

Supported datatypes

pgcopy supports the following PostgreSQL scalar types:

  • bool
  • smallint
  • integer
  • bigint
  • real
  • double precision
  • char
  • varchar
  • text
  • bytea
  • date
  • timestamp
  • timestamp with time zone
  • numeric
  • json
  • jsonb
  • uuid
  • arrays

Documentation

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.

Files for pgcopy, version 1.4.0
Filename, size File type Python version Upload date Hashes
Filename, size pgcopy-1.4.0-py2.py3-none-any.whl (11.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size pgcopy-1.4.0.tar.gz (11.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page