Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sql.postgres.driver

import sql.postgres.driver

sql lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled sql.postgres.driver.* needs import sql.postgres.driver.

Opening PostgreSQL connections: reading a connection string, establishing the socket, upgrading it to TLS when asked, and authenticating.

Constants

DEFAULT_PORT

sql.postgres.DEFAULT_PORT = 5432

The port a PostgreSQL server listens on unless told otherwise.

DEFAULT_TIMEOUT

sql.postgres.driver.DEFAULT_TIMEOUT = 30000

How long to wait for the socket and for each read, in milliseconds.

MAX_PARAMETERS

sql.postgres.MAX_PARAMETERS = 65535

Most parameters one statement can bind. The protocol counts them in a signed 16 bit field, so this is a hard limit rather than a configured one.

SSL_MODES

sql.postgres.SSL_MODES = [...]

What sslmode can be.

disable never uses TLS. prefer uses it when the server offers it and carries on without when it does not. require insists, and fails when the server refuses.

Classes

PostgresDriver

class sql.postgres.PostgresDriver < Driver

Opens PostgreSQL connections.

PostgresDriver.name()

sql.postgres.PostgresDriver.name()

PostgresDriver.schemes()

sql.postgres.PostgresDriver.schemes()

PostgresDriver.capabilities()

sql.postgres.PostgresDriver.capabilities() -> dict

What PostgreSQL can do.

last_insert_id is false, which is the one difference most visible from above: an insert that wants its id back gets a RETURNING clause instead, which Connection.insert() adds.

Returns dict

PostgresDriver.parse_dsn()

sql.postgres.PostgresDriver.parse_dsn(dsn) -> dict

Reads a connection string, in either of the two forms PostgreSQL’s own tools accept.

A URI:

postgres://alice:secret@db.example.com:5432/app?sslmode=require
postgresql://localhost/app

Or keywords:

host=localhost port=5432 dbname=app user=alice password=secret

Anything absent is filled in the way libpq fills it: the user defaults to postgres, the database to the user’s name, the host to localhost and the port to 5432.

Parameters

  • dsn (string|dict)

Returns dict

Raises ConnectionError if the string cannot be read.

PostgresDriver.connect()

sql.postgres.PostgresDriver.connect(options: dict) -> PostgresConnection

Opens the connection and authenticates.

Parameters

  • options (dict) — From parse_dsn().

Returns PostgresConnection


2026, Richard Ore and Zuri contributors