Skip to content

py-postgresql: Query a PostgreSQL database with Python 3 using the PQv3 protocol.

License

Notifications You must be signed in to change notification settings

python-postgres/fe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6ce9885 · Mar 9, 2025
Mar 9, 2025
Dec 19, 2020
Apr 22, 2010
Sep 18, 2020
Jun 9, 2018
Aug 3, 2018
Mar 14, 2023
Feb 4, 2023
Dec 6, 2020
May 2, 2017

Repository files navigation

About

py-postgresql is a Python 3 package providing modules for working with PostgreSQL. Primarily, a high-level driver for querying databases.

While py-postgresql is still usable for many purposes, asyncpg and PostgREST are likely more suitable for most applications:

py-postgresql, currently, does not have direct support for high-level async interfaces provided by recent versions of Python. Future versions may change this.

Advisory

In v2.0, many, potentially breaking, changes are planned. If you have automated installations using PyPI, make sure that they specify a major version.

  • Support for older versions of PostgreSQL and Python will be removed. This will allow the driver to defer version parsing fixing (#109), and better prepare for future versions.
  • The connection establishment strategy will be simplified to only performing one attempt. sslmode parameter should be considered deprecated. v1.4 will provide a new security parameter implying sslmode=require. See (#122) and (#75).
  • StoredProcedure will be removed. See (#80).

Installation

From PyPI using pip:

python3 -m pip install py-postgresql

From GitHub using a full clone:

git clone https://github.com/python-postgres/fe.git
cd fe
python3 ./setup.py install

Basic Usage

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)

REPL with connection bound to db builtin:

python3 -m postgresql.bin.pg_python -I 'pq://postgres@localhost:5423/postgres'

Documentation

Related

About

py-postgresql: Query a PostgreSQL database with Python 3 using the PQv3 protocol.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published