Skip to content

PostgreSQL guide

Installation

Install the PostgreSQL extra:

pip install adbc-poolhouse[postgresql]

Or with uv:

uv add "adbc-poolhouse[postgresql]"

Connection

PostgreSQLConfig supports URI-based and individual field connection specification.

URI mode

from adbc_poolhouse import PostgreSQLConfig, create_pool

config = PostgreSQLConfig(
    uri="postgresql://me:s3cret@db.example.com:5432/mydb?sslmode=require",  # pragma: allowlist secret
)
pool = create_pool(config)

Individual fields

from adbc_poolhouse import PostgreSQLConfig, create_pool

config = PostgreSQLConfig(
    host="db.example.com",
    user="me",
    password="s3cret",  # pragma: allowlist secret
    database="mydb",
    sslmode="require",
)
pool = create_pool(config)

port, password, and sslmode are all optional. An omitted port is left out of the connection URI entirely, so PostgreSQL's own default of 5432 applies.

Loading from environment variables

PostgreSQLConfig reads fields from environment variables with the POSTGRESQL_ prefix:

export POSTGRESQL_HOST=db.example.com
export POSTGRESQL_USER=me
export POSTGRESQL_PASSWORD=s3cret  # pragma: allowlist secret
export POSTGRESQL_DATABASE=mydb
config = PostgreSQLConfig()  # reads from env
pool = create_pool(config)

See also