Skip to main content

PostgreSQL driver and tools library.

Project description


In v1.3, postgresql.driver.dbapi20.connect will now raise ClientCannotConnectError directly. Exception traps around connect should still function, but the __context__ attribute on the error instance will be None in the usual failure case as it is no longer incorrectly chained. Trapping ClientCannotConnectError ahead of Error should allow both cases to co-exist in the event that data is being extracted from the ClientCannotConnectError.

py-postgresql is a set of Python modules providing interfaces to various parts of PostgreSQL. Primarily, it provides a pure-Python driver with some C optimizations for querying a PostgreSQL database.


  • Prepared Statement driven interfaces.
  • Cluster tools for creating and controlling a cluster.
  • Support for most PostgreSQL types: composites, arrays, numeric, lots more.
  • COPY support.

Sample PG-API Code:

>>> import postgresql
>>> db ='pq://user:password@host:port/database')
>>> db.execute("CREATE TABLE emp (emp_first_name text, emp_last_name text, emp_salary numeric)")
>>> make_emp = db.prepare("INSERT INTO emp VALUES ($1, $2, $3)")
>>> make_emp("John", "Doe", "75,322")
>>> with db.xact():
...  make_emp("Jane", "Doe", "75,322")
...  make_emp("Edward", "Johnson", "82,744")

There is a DB-API 2.0 module as well:


However, PG-API is recommended as it provides greater utility.

Once installed, try out the pg_python console script:

$ python3 -m postgresql.bin.pg_python -h localhost -p port -U theuser -d database_name

If a successful connection is made to the remote host, it will provide a Python console with the database connection bound to the db name.

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 py-postgresql, version 1.2.2
Filename, size File type Python version Upload date Hashes
Filename, size py-postgresql-1.2.2.tar.gz (272.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page