psqlpy Adapter¶
from sqlspec.adapters.psqlpy import (
PsqlpyConfig,
PsqlpyConnectionParams,
PsqlpyDriver,
PsqlpyDriverFeatures,
PsqlpyExceptionHandler,
PsqlpyPoolParams,
)
Rust-backed asynchronous PostgreSQL adapter built on psqlpy. Inherited execution methods are documented on AsyncDriverAdapterBase. See the PostgreSQL (psqlpy) Setup Guide for usage examples.
Configuration & Parameters¶
PsqlpyConfig
¶
Bases: AsyncDatabaseConfig[PsqlpyConnection, 'ConnectionPool', PsqlpyDriver]
Configuration for Psqlpy asynchronous database connections.
PsqlpyConnectionParams
¶
Bases: TypedDict
Psqlpy connection parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
dsn |
NotRequired[str]
|
PostgreSQL connection URI ( |
username |
NotRequired[str]
|
PostgreSQL role name used for authentication. |
password |
NotRequired[str]
|
Password for |
db_name |
NotRequired[str]
|
Target PostgreSQL database name. |
host |
NotRequired[str]
|
Database server hostname or IP address. |
port |
NotRequired[int]
|
Database server TCP port (defaults to |
connect_timeout_sec |
NotRequired[int]
|
Whole-second component of the TCP connection establishment timeout. |
connect_timeout_nanosec |
NotRequired[int]
|
Sub-second nanosecond component of the connection establishment timeout. |
tcp_user_timeout_sec |
NotRequired[int]
|
Whole-second TCP unacknowledged transmission timeout. |
tcp_user_timeout_nanosec |
NotRequired[int]
|
Sub-second nanosecond component of the TCP user timeout. |
keepalives |
NotRequired[bool]
|
Enable TCP keepalive probes on client sockets. |
keepalives_idle_sec |
NotRequired[int]
|
Idle duration in seconds before sending the first TCP keepalive probe. |
keepalives_idle_nanosec |
NotRequired[int]
|
Nanosecond component of the TCP keepalive idle interval. |
keepalives_interval_sec |
NotRequired[int]
|
Interval in seconds between consecutive unacknowledged TCP keepalive probes. |
keepalives_interval_nanosec |
NotRequired[int]
|
Nanosecond component of the TCP keepalive probe interval. |
keepalives_retries |
NotRequired[int]
|
Maximum unacknowledged TCP keepalive probes before dropping the connection. |
ssl_mode |
NotRequired[str]
|
TLS negotiation policy ( |
ca_file |
NotRequired[str]
|
Path to a PEM root CA bundle used to verify server certificates. |
target_session_attrs |
NotRequired[str]
|
Required server session state for multi-host routing (such as |
options |
NotRequired[str]
|
Command-line startup GUC options sent to the PostgreSQL backend. |
application_name |
NotRequired[str]
|
Application identifier reported in |
client_encoding |
NotRequired[str]
|
Client character set encoding (defaults to |
gssencmode |
NotRequired[str]
|
GSSAPI transport encryption mode ( |
sslnegotiation |
NotRequired[str]
|
PostgreSQL 17+ TLS handshake mode ( |
sslcompression |
NotRequired[str]
|
TLS compression setting forwarded to |
sslcert |
NotRequired[str]
|
Path to the client TLS certificate file. |
sslkey |
NotRequired[str]
|
Path to the client TLS private key file. |
sslpassword |
NotRequired[str]
|
Passphrase unlocking an encrypted |
sslrootcert |
NotRequired[str]
|
Path to the trusted root certificate authority file. |
sslcrl |
NotRequired[str]
|
Path to the certificate revocation list file. |
require_auth |
NotRequired[str]
|
Comma-separated list of acceptable server authentication methods. |
channel_binding |
NotRequired[str]
|
SCRAM channel binding requirement ( |
krbsrvname |
NotRequired[str]
|
Kerberos service principal name for GSSAPI authentication. |
gsslib |
NotRequired[str]
|
GSSAPI library implementation selector. |
gssdelegation |
NotRequired[str]
|
Whether to delegate GSSAPI credentials to the PostgreSQL server. |
service |
NotRequired[str]
|
Service profile name defined in |
load_balance_hosts |
NotRequired[str]
|
Host ordering policy across multi-host configurations ( |
PsqlpyPoolParams
¶
Bases: PsqlpyConnectionParams
Psqlpy pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
hosts |
NotRequired[list[str]]
|
Ordered list of PostgreSQL hostnames for multi-host failover or load balancing. |
ports |
NotRequired[list[int]]
|
Port numbers corresponding to |
conn_recycling_method |
NotRequired[str]
|
Pool connection reset strategy (such as |
max_db_pool_size |
NotRequired[int]
|
Maximum number of concurrent connections held by |
max_cached_statement_lifetime |
NotRequired[int]
|
Maximum lifetime in seconds for cached prepared statements. |
configure |
NotRequired[Callable[..., Any]]
|
Optional pool connection configuration callback. |
extra |
NotRequired[dict[str, Any]]
|
Additional keyword options passed directly to |
PsqlpyDriverFeatures
¶
Bases: TypedDict
Optional driver feature flags, extension detection, and pooler settings for Psqlpy.
Attributes:
| Name | Type | Description |
|---|---|---|
enable_cast_detection |
NotRequired[bool]
|
Use SQL type casts in statements to coerce JSON, UUID, and temporal bind values (defaults to |
enable_pgvector |
NotRequired[bool]
|
Detect the PostgreSQL |
enable_paradedb |
NotRequired[bool]
|
Detect |
enable_pg_textsearch |
NotRequired[bool]
|
Detect |
enable_alloydb_columnar |
NotRequired[bool]
|
Enable |
pooler_mode |
NotRequired[Literal['session', 'transaction', 'statement', 'auto'] | None]
|
External pooler compatibility mode; executes queries with |
pgbouncer |
NotRequired[bool]
|
Alias for |
pgbouncer_mode |
NotRequired[bool]
|
Alias for |
direct_dsn |
NotRequired[str | Mapping[str, Any] | None]
|
Direct PostgreSQL DSN or connection mapping bypassing the pooler for migrations and |
json_serializer |
NotRequired[Callable[[Any], str]]
|
Custom JSON serializer applied to statement parameter conversion (defaults to |
json_deserializer |
NotRequired[Callable[[str], Any]]
|
Custom JSON deserializer retained alongside |
on_connection_create |
NotRequired[Callable[[PsqlpyConnection], Awaitable[None]]]
|
Async callback invoked once per physical |
enable_events |
NotRequired[bool]
|
Enable SQLSpec event channel pub/sub support (defaults to |
events_backend |
NotRequired[Literal['notify', 'notify_queue', 'poll_queue']]
|
Event transport backend ( |
Driver & Pool¶
PsqlpyDriver
¶
Bases: AsyncDriverAdapterBase
PostgreSQL driver implementation using psqlpy.
Provides parameter style conversion, type coercion, error handling, and transaction management.
PsqlpyExceptionHandler
¶
Bases: BaseAsyncExceptionHandler
Async context manager for handling psqlpy database exceptions.
Maps PostgreSQL SQLSTATE error codes to SQLSpec exceptions stored on
pending_exception.
Extension Stores¶
PsqlpyStore
¶
Bases: BaseSQLSpecStore['PsqlpyConfig']
PostgreSQL session store using Psqlpy driver.
Implements server-side session storage for Litestar using PostgreSQL via the Psqlpy driver (Rust-based async driver). Provides efficient session management with: - Native async PostgreSQL operations via Rust - UPSERT support using ON CONFLICT - Automatic expiration handling - Efficient cleanup of expired sessions
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PsqlpyConfig
|
PsqlpyConfig instance. |
required |
PsqlpyADKStore
¶
Bases: BaseAsyncADKStore['PsqlpyConfig']
PostgreSQL ADK store using Psqlpy driver.
Implements session and event storage for Google Agent Development Kit
using PostgreSQL via the high-performance Rust-based psqlpy driver.
Events are stored as a single JSONB blob (event_data) alongside
indexed scalar columns for efficient querying.
Provides
- Session state management with JSONB storage
- Full-fidelity event storage via
event_dataJSONB column - Atomic
append_event_and_update_statefor durable session mutations - Microsecond-precision timestamps with TIMESTAMPTZ
- Foreign key constraints with cascade delete
- GIN indexes for JSONB queries
- HOT updates with FILLFACTOR 80
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
PsqlpyConfig
|
PsqlpyConfig with extension_config["adk"] settings. |
required |
PsqlpyADKMemoryStore
¶
PsqlpyEventQueueStore
¶
Bases: BaseEventQueueStore[PsqlpyConfig]
Provide PostgreSQL column mappings for the queue table.
PostgreSQL uses JSONB for efficient binary JSON storage with indexing support, and TIMESTAMPTZ for timezone-aware timestamps.
PsqlpyEventsBackend
¶
Native LISTEN/NOTIFY backend for psqlpy adapters.