Skip to content

PostgreSQL guide

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 defaults to 5432 when omitted. password and sslmode are optional.

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