py-postgresql is a Python 3 package providing modules for working with PostgreSQL. Primarily, a high-level driver for querying databases.
For a high performance async interface, MagicStack's asyncpg http://github.com/MagicStack/asyncpg should be considered.
py-postgresql, currently, does not have direct support for high-level async interfaces provided by recent versions of Python. Future versions may change this.
postgresql.driver.dbapi20.connect will now raise
Exception traps around connect should still function, but the
on the error instance will be
None in the usual failure case as it is no longer
incorrectly chained. Trapping
ClientCannotConnectError ahead of
allow both cases to co-exist in the event that data is being extracted from
In v2.0, support for older versions of PostgreSQL and Python will be removed. If you have automated installations using PyPI, make sure that they specify a major version.
$ pip install py-postgresql
From a clone:
$ git clone https://github.com/python-postgres/fe.git $ cd fe $ python3 ./setup.py install # Or use in-place without installation(PYTHONPATH).
import postgresql db = postgresql.open('pq://user:password@host:port/database') get_table = db.prepare("SELECT * from information_schema.tables WHERE table_name = $1") print(get_table("tables")) # Streaming, in a transaction. with db.xact(): for x in get_table.rows("tables"): print(x)