pydrda Adapter¶
from sqlspec.adapters.pydrda import (
PydrdaAsyncConfig,
PydrdaAsyncDriver,
PydrdaAsyncExceptionHandler,
PydrdaAsyncGlobalVariableStrategy,
PydrdaAsyncPoolParams,
PydrdaConnectionParams,
PydrdaDriverFeatures,
PydrdaPoolParams,
PydrdaSyncConfig,
PydrdaSyncDriver,
PydrdaSyncExceptionHandler,
PydrdaSyncGlobalVariableStrategy,
)
Synchronous and asynchronous IBM Db2 LUW adapters built on pure-Python DRDA transport over pydrda (>= 0.6.4), providing linux/aarch64 support without ibm_db and native asyncio streams via drda.aio. Inherited execution methods are documented on SyncDriverAdapterBase and AsyncDriverAdapterBase. See the IBM Db2 Setup Guide for usage examples and the IBM Db2 Data Dictionary & SQL Catalog.
Configuration & Parameters¶
PydrdaSyncConfig
¶
Bases: SyncDatabaseConfig[PydrdaSyncConnection, PydrdaSyncConnectionPool, PydrdaSyncDriver]
Configuration for IBM Db2 synchronous connections over pydrda.
PydrdaAsyncConfig
¶
Bases: AsyncDatabaseConfig[PydrdaAsyncConnection, PydrdaAsyncConnectionPool, PydrdaAsyncDriver]
Configuration for IBM Db2 asynchronous connections over drda.aio.AsyncConnection.
PydrdaConnectionParams
¶
Bases: TypedDict
IBM Db2 DRDA (pydrda) connection parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
host |
NotRequired[str]
|
Db2 server hostname or IP address. |
port |
NotRequired[int]
|
Db2 DRDA TCP listener port (defaults to |
database |
NotRequired[str]
|
Target Db2 database name. |
user |
NotRequired[str]
|
Authentication username. |
password |
NotRequired[str]
|
Authentication password. |
use_ssl |
NotRequired[bool]
|
Enable TLS transport encryption (defaults to |
ssl_client_cert_path |
NotRequired[str]
|
Optional TLS client certificate path forwarded to |
timeout |
NotRequired[float]
|
Socket timeout in seconds. |
current_schema |
NotRequired[str]
|
Default SQL schema applied via |
autocommit |
NotRequired[bool]
|
Emulated autocommit baseline applied outside explicit transactions (defaults to |
dsn |
NotRequired[str]
|
Base |
PydrdaPoolParams
¶
Bases: PydrdaConnectionParams
IBM Db2 DRDA (pydrda) thread-local and task-scoped connection pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
pool_recycle_seconds |
NotRequired[int]
|
Maximum connection age in seconds before replacement (defaults to |
health_check_interval |
NotRequired[float]
|
Idle seconds elapsed before a pooled connection is pinged on reuse (defaults to |
PydrdaAsyncPoolParams
¶
Bases: PydrdaPoolParams
IBM Db2 DRDA (pydrda) bounded native asyncio connection pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
max_size |
NotRequired[int]
|
Maximum number of connections checked out or opening concurrently (defaults to |
acquire_timeout |
NotRequired[float]
|
Maximum seconds to wait for a free connection before raising |
PydrdaDriverFeatures
¶
Bases: TypedDict
IBM Db2 DRDA (pydrda) driver feature flags controlling JSON codecs, column casing, and event queues.
Attributes:
| Name | Type | Description |
|---|---|---|
tenant_strategy |
NotRequired[SyncTenantStrategy | AsyncTenantStrategy | TenantStrategyShorthand | None]
|
Opt-in tenant strategy, or the |
json_serializer |
NotRequired[Callable[[Any], str]]
|
Serializer converting dict/list parameters to JSON text (defaults to |
json_deserializer |
NotRequired[Callable[[str], Any]]
|
Deserializer parsing JSON text payloads (defaults to |
on_connection_create |
NotRequired[Callable[[Any], Any]]
|
Callback invoked with the raw |
enable_events |
NotRequired[bool]
|
Enable SQLSpec table-backed event channel support. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Event queue backend name ( |
enable_lowercase_column_names |
NotRequired[bool]
|
Normalize unquoted uppercase Db2 column names to lowercase (defaults to |
Tenant Strategies¶
Set driver_features={"tenant_strategy": "rcac"}; "global_variable", "default", and True select the same mode-specific strategy. The strategy writes the tenant identity into a session global variable that row and column access control (RCAC) permissions and masks read. The default variable is APP.CURRENT_TENANT_ID; pass tenant_variable= and variable_keys= to an explicit strategy to use other schema-qualified variables. Names are validated as ordinary identifiers and folded to upper case; values are always bound.
A DBA provisions the variable and the policy, and grants the application READ and WRITE on the variable:
CREATE VARIABLE APP.CURRENT_TENANT_ID VARCHAR(256) DEFAULT NULL;
CREATE PERMISSION APP.PROJECTS_TENANT ON APP.PROJECTS
FOR ROWS WHERE TENANT_ID = APP.CURRENT_TENANT_ID
ENFORCED FOR ALL ACCESS ENABLE;
ALTER TABLE APP.PROJECTS ACTIVATE ROW ACCESS CONTROL;
Session global variable values are not affected by COMMIT or ROLLBACK. Checkout reads the previous values, assigns the payload with one SET, and reads the values back; checkin assigns the captured values and verifies them again. A failed verification disposes of the connection instead of returning it for reuse. Standalone create_connection() is rejected in tenant mode. Tenant leases keep the native commit behavior: sessions roll back unfinished work before release, as they do without a tenant strategy.
Missing tenant identity raises TenantContextError before acquisition. Failed cleanup raises TenantCleanupError when no body exception is pending; otherwise the body error keeps its identity and receives a cleanup note. See Multi-Tenancy and Tenant Operations.
PydrdaSyncGlobalVariableStrategy
¶
Bases: _PydrdaGlobalVariables
Set, verify, and restore Db2 session global variables on a synchronous DRDA connection.
RCAC permissions and masks read the variables; database policies enforce row access. Checkin unconditionally rolls back the verification unit of work because DRDA always operates in manual-commit mode without an autocommit inspection API.
__init__
¶
Configure the owned global variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tenant_variable
|
object
|
Schema-qualified global variable receiving the tenant identity. |
DEFAULT_PYDRDA_TENANT_VARIABLE
|
variable_keys
|
Mapping[str, str] | None
|
Payload variable names mapped to schema-qualified global variables. |
None
|
Raises:
| Type | Description |
|---|---|
ImproperConfigurationError
|
A name is invalid or two keys target the same variable. |
checkout
¶
Capture the previous values, assign the payload, and verify the server values.
checkin
¶
Restore the captured values, verify them, and roll back the verification UOW.
PydrdaAsyncGlobalVariableStrategy
¶
Bases: _PydrdaGlobalVariables
Set, verify, and restore Db2 session global variables on an asynchronous DRDA connection.
RCAC permissions and masks read the variables; database policies enforce row access.
Cursor cleanup executes outside except blocks for predictable coroutine cleanup, and
checkin unconditionally rolls back the verification unit of work.
__init__
¶
Configure the owned global variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tenant_variable
|
object
|
Schema-qualified global variable receiving the tenant identity. |
DEFAULT_PYDRDA_TENANT_VARIABLE
|
variable_keys
|
Mapping[str, str] | None
|
Payload variable names mapped to schema-qualified global variables. |
None
|
Raises:
| Type | Description |
|---|---|
ImproperConfigurationError
|
A name is invalid or two keys target the same variable. |
checkout
¶
Capture the previous values, assign the payload, and verify the server values.
checkin
¶
Restore the captured values, verify them, and roll back the verification UOW.
Driver, Pool & Data Dictionary¶
PydrdaSyncDriver
¶
PydrdaAsyncDriver
¶
PydrdaSyncExceptionHandler
¶
Bases: BaseSyncExceptionHandler
Context manager that maps pyDRDA errors to SQLSpec exceptions.
Catches PydrdaError, PydrdaDisconnectByPeer, and OSError. Exceptions outside
PYDRDA_DRIVER_ERRORS propagate unchanged.
PydrdaAsyncExceptionHandler
¶
Bases: BaseAsyncExceptionHandler
Async context manager that maps pyDRDA errors to SQLSpec exceptions.
Catches PydrdaError, PydrdaDisconnectByPeer, and OSError. Exceptions outside
PYDRDA_DRIVER_ERRORS propagate unchanged.
PydrdaSyncDataDictionary
¶
Bases: Db2SyncDataDictionary
IBM Db2 sync data dictionary for pyDRDA metadata reflection.
PydrdaAsyncDataDictionary
¶
Bases: Db2AsyncDataDictionary
IBM Db2 async data dictionary for pyDRDA metadata reflection.
Extension Stores & Configs¶
PydrdaSyncStore
¶
Bases: _PydrdaLitestarStoreMixin, BaseSQLSpecStore['PydrdaSyncConfig']
IBM Db2-backed session store using synchronous pyDRDA sessions.
Every timestamp written or compared is a naive-UTC value bound from Python, so expiry does
not depend on the server's time zone. Expired-session cleanup counts before deleting inside
one unit of work so negative pydrda cursor rowcounts still report accurate totals.
PydrdaAsyncStore
¶
Bases: _PydrdaLitestarStoreMixin, BaseSQLSpecStore['PydrdaAsyncConfig']
IBM Db2-backed session store using asynchronous pyDRDA sessions.
Runs the same statements with the same parameters as PydrdaSyncStore; every timestamp
written or compared is a naive-UTC value bound from Python, and expired-session cleanup
counts before deleting inside one unit of work for negative pydrda rowcounts.
PydrdaSyncADKStore
¶
Bases: _PydrdaADKStoreMixin, BaseSyncADKStore[PydrdaSyncConfig]
Synchronous IBM Db2 DRDA (pydrda) ADK session/event store.
PydrdaAsyncADKStore
¶
Bases: _PydrdaADKStoreMixin, BaseAsyncADKStore[PydrdaAsyncConfig]
Asynchronous IBM Db2 DRDA (pydrda) ADK session/event store.
PydrdaSyncADKMemoryStore
¶
Bases: _PydrdaADKMemoryStoreMixin, BaseSyncADKMemoryStore[PydrdaSyncConfig]
IBM Db2 DRDA (pydrda) ADK memory store for synchronous configs.
PydrdaAsyncADKMemoryStore
¶
Bases: _PydrdaADKMemoryStoreMixin, BaseAsyncADKMemoryStore[PydrdaAsyncConfig]
IBM Db2 DRDA (pydrda) ADK memory store for asynchronous configs.
PydrdaSyncEventQueueStore
¶
Bases: _PydrdaEventStoreMixin, BaseEventQueueStore[PydrdaSyncConfig]
IBM Db2 pyDRDA event queue store for synchronous configs.
PydrdaAsyncEventQueueStore
¶
Bases: _PydrdaEventStoreMixin, BaseEventQueueStore[PydrdaAsyncConfig]
IBM Db2 pyDRDA event queue store for asynchronous configs.