Skip to content

oracledb Adapter

from sqlspec.adapters.oracledb import (
    OracleAsyncConfig,
    OracleAcquireOptions,
    OracleAsyncClientContextStrategy,
    OracleAsyncEndUserSecurityStrategy,
    OracleAsyncSessionlessTransactionContext,
    OracleEndUserSecurityConfig,
    OraclePluginName,
    OraclePoolBoundary,
    OraclePurityInput,
    OracleShardResolver,
    OracleSyncClientContextStrategy,
    OracleSyncEndUserSecurityStrategy,
    OracleSyncSessionlessTransactionContext,
    OracleTransactionPriority,

    OracleAsyncDriver,
    OracleAsyncExceptionHandler,
    OracleConnectionParams,
    OracleDriverFeatures,
    OracleEndpoint,
    OraclePoolParams,
    OracleSessionContextConfig,
    OracleSyncConfig,
    OracleSyncDriver,
    OracleSyncExceptionHandler,
    OracleTopologyConfig,
    OracleSyncIdentifierStrategy,
    OracleAsyncIdentifierStrategy,
    OracleSyncVPDStrategy,
    OracleAsyncVPDStrategy,
)

Synchronous and asynchronous Oracle Database adapters built on python-oracledb (Thin and Thick modes) with VECTOR, JSON, LOB, and Advanced Queuing support. Inherited execution methods are documented on SyncDriverAdapterBase and AsyncDriverAdapterBase. See the Oracle Database Setup Guide for wallet, pool, and vector configuration, and the Oracle Data Dictionary & SQL Catalog.

Configuration & Parameters

The connection and pool parameter table lists every supported key, type, and default.

OracleSyncConfig

Bases: SyncDatabaseConfig[OracleSyncConnection, 'OracleSyncConnectionPool', OracleSyncDriver]

Configuration for Oracle synchronous database connections.

OracleAsyncConfig

Bases: AsyncDatabaseConfig[OracleAsyncConnection, 'OracleAsyncConnectionPool', OracleAsyncDriver]

Configuration for Oracle asynchronous database connections.

OracleConnectionParams

Bases: TypedDict

OracleDB connection parameters forwarded to python-oracledb.

OraclePoolParams

Bases: OracleConnectionParams

OracleDB session pool parameters extending OracleConnectionParams.

OracleDriverFeatures

Bases: TypedDict

Oracle driver feature flags controlling VECTOR/UUID codecs, LOB coercion, and enterprise hooks.

Native async pipeline execution is runtime-gated on Oracle Database 23ai/26ai+ in Thin mode and opted out via stack_native_disabled.

Attributes:

Name Type Description
retry_on_standby_lag NotRequired[bool]

Allow primary fallback on standby checkout lag or switchover.

plugins NotRequired[Sequence[OraclePluginName | str]]

Optional cloud configuration or token plugins imported lazily.

params_hooks NotRequired[Sequence[Callable[[Any], None]]]

Native parameter hooks registered idempotently before connecting.

enable_auto_state_tagging NotRequired[bool]

Synthesize and reuse Thick pool session state tags (defaults to True).

enable_numpy_vectors NotRequired[bool]

Register bidirectional NumPy ndarray handlers for Oracle 23ai+ VECTOR columns (defaults to True when NumPy is installed).

enable_lowercase_column_names NotRequired[bool]

Normalize unquoted uppercase Oracle column names to lowercase while preserving quoted aliases (defaults to True).

enable_uuid_binary NotRequired[bool]

Convert Python UUID values to and from RAW(16) columns.

vector_return_format NotRequired[OracleVectorReturnFormat]

Decoded type for dense VECTOR columns ('numpy', 'list', or 'array').

oracle_varchar2_byte_limit NotRequired[int]

UTF-8 byte threshold above which str parameters bind as DB_TYPE_CLOB (defaults to 4000).

oracle_raw_byte_limit NotRequired[int]

Byte threshold above which bytes parameters bind as DB_TYPE_BLOB (defaults to 2000).

arraysize NotRequired[int]

Per-cursor arraysize row fetch buffer override.

prefetchrows NotRequired[int]

Per-cursor prefetchrows initial round-trip prefetch count override.

fetch_lobs NotRequired[bool]

Return LOB columns as locator objects when True or inline str/bytes when False.

fetch_decimals NotRequired[bool]

Return NUMBER columns as decimal.Decimal values when True.

on_connection_create NotRequired[Callable[..., Any]]

Hook (connection, tag) invoked after built-in JSON, VECTOR, and UUID handlers are registered.

enable_events NotRequired[bool]

Enable SQLSpec event channels (separate from connection_config['events'] FAN/CQN notifications).

events_backend NotRequired[OracleEventsBackend]

Event queue backend ('poll_queue' default, 'aq', or 'txeventq').

enable_direct_path_load NotRequired[bool]

Route load_from_arrow through Thin-mode Connection.direct_path_load with executemany fallback (defaults to True).

tenant_strategy NotRequired[TenantStrategy | OracleTenantStrategyShorthand | None]

Opt-in tenant strategy, or the "identifier" shorthand, applied to every session and connection lease.

session_context_hook NotRequired[OracleSessionContextConfig | dict[str, Any]]

Declarative DBMS_SESSION / CLIENT_IDENTIFIER context applied on checkout and cleared on release.

sharding_key_variable NotRequired[str]

Tenant variable carrying the primary shard key.

super_sharding_key_variable NotRequired[str]

Tenant variable carrying the super-shard key.

shard_resolver NotRequired[OracleShardResolver]

Resolve primary and super-shard keys from the captured tenant payload.

use_tenant_id_as_sharding_key NotRequired[bool]

Route directly by captured tenant identity in Thick mode.

enable_otel_trace_context NotRequired[bool]

Piggyback W3C trace headers on supported Oracle connections.

enable_session_tracing NotRequired[bool]

Piggyback active correlation and trace identifiers onto module, action, client_identifier, and econtext_id in zero extra RTTs.

dbms_cloud_credential NotRequired[str | None]

Default DBMS_CLOUD credential name used for server-side DBMS_CLOUD.COPY_DATA object-store loads.

OracleTopologyConfig

Typed Oracle Net multi-endpoint topology configuration for RAC, Data Guard, and CMAN.

OracleEndpoint

Typed Oracle Net listener endpoint for multi-endpoint TNS descriptors.

OracleSessionContextConfig

Declarative Oracle session context, EBR edition, NLS, EBS, APEX, and VPD configuration.

Tenant Strategies

Set tenant_strategy to "default", "identifier", or True for client-identifier metadata. VPD requires an explicit mode-specific VPD strategy with trusted set_procedure, clear_procedure, namespace, and attribute names, plus an administrator-provisioned package and database policy. Confirm edition and licensing with your DBA. Identity alone does not enforce row access.

The strategy composes existing session hooks (automatically binding driver_features["session_context_hook"] when no explicit strategy-level hook is passed, and rejecting mismatched explicit hooks), preserves NLS/edition/time-zone behavior, and verifies the server identifier and VPD context. Oracle identifiers must fit in 64 UTF-8 bytes. Cleanup failure physically drops pooled connections. Both providers require an explicit tenant or bypass; standalone create_connection() is rejected in tenant mode. Hook calls and server verification can require multiple round trips; supported async Thin paths can batch checkout and verification in a native pipeline. Native client-context and end-user security strategies are documented below.

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.

OracleSyncIdentifierStrategy

Apply an Oracle client identifier, preserving configured session hooks.

Client identifiers are metadata. Database policies must enforce row access.

__init__
__init__(hook=None, *, variable_keys=())
checkout
checkout(connection, payload)

Apply the captured payload and verify the identifier on the server.

checkin
checkin(connection, state)

Clear the identifier and verify that the server has no tenant value.

OracleAsyncIdentifierStrategy

Apply and verify a client identifier on an asynchronous Oracle connection.

__init__
__init__(hook=None, *, variable_keys=())
checkout
checkout(connection, payload)

Apply the captured payload and verify the identifier on the server.

checkin
checkin(connection, state)

Clear the identifier and verify that the server has no tenant value.

OracleSyncVPDStrategy

Bases: OracleSyncIdentifierStrategy

Apply a tenant through an administrator-provisioned trusted context package.

__init__
__init__(
    *,
    set_procedure,
    clear_procedure,
    namespace,
    attribute,
    variable_keys=(),
    hook=None,
)
checkout
checkout(connection, payload)

Bind the identifier, set the trusted context, and verify both in one read.

checkin
checkin(connection, state)

Clear the trusted context, then the identifier, and verify both in one read.

OracleAsyncVPDStrategy

Bases: OracleAsyncIdentifierStrategy

Apply a trusted application context on an asynchronous Oracle connection.

__init__
__init__(
    *,
    set_procedure,
    clear_procedure,
    namespace,
    attribute,
    variable_keys=(),
    hook=None,
)
checkout
checkout(connection, payload)

Bind the identifier, set the trusted context, and verify both in one read.

checkin
checkin(connection, state)

Clear the trusted context, then the identifier, and verify both in one read.

Driver, Pool & Data Dictionary

OracleSyncDriver

Bases: SyncDriverAdapterBase

Synchronous Oracle Database driver.

Provides Oracle Database connectivity with parameter style conversion, error handling, and transaction management.

OracleAsyncDriver

Bases: AsyncDriverAdapterBase

Asynchronous Oracle Database driver.

Provides Oracle Database connectivity with parameter style conversion, error handling, and transaction management for async operations.

OracleSyncExceptionHandler

Bases: BaseSyncExceptionHandler

Synchronous context manager for handling Oracle database exceptions.

Maps Oracle ORA-XXXXX error codes to SQLSpec exceptions stored on pending_exception.

OracleAsyncExceptionHandler

Bases: BaseAsyncExceptionHandler

Async context manager for handling Oracle database exceptions.

Maps Oracle ORA-XXXXX error codes to SQLSpec exceptions stored on pending_exception.

OracledbSyncDataDictionary

Bases: SyncDataDictionaryBase

Oracle-specific sync data dictionary.

OracledbAsyncDataDictionary

Bases: AsyncDataDictionaryBase

Oracle-specific async data dictionary.

Extension Stores & Configs

OracleLitestarConfig

Bases: LitestarConfig

Oracle-specific Litestar settings.

Use inside extension_config["litestar"] with this adapter's session store.

Attributes:

Name Type Description
in_memory NotRequired[bool]

Enable Oracle INMEMORY table storage.

compression NotRequired[OracleLitestarCompressionConfig]

Session table compression settings.

partitioning NotRequired[OracleLitestarPartitionConfig]

Session table partition settings.

table_options NotRequired[str]

Additional session table DDL options.

OracleSyncStore

Bases: BaseSQLSpecStore['OracleSyncConfig']

Oracle session store using sync OracleDB driver.

Implements server-side session storage for Litestar using Oracle Database via the synchronous python-oracledb driver. Runs operations in worker threads to provide an async interface compatible with the Store protocol.

Provides efficient session management with
  • Sync operations wrapped for async compatibility
  • MERGE statement for atomic UPSERT
  • Automatic expiration handling
  • Efficient cleanup of expired sessions
  • Optional In-Memory Column Store support (requires Oracle Database In-Memory license)

OracleAsyncStore

Bases: BaseSQLSpecStore['OracleAsyncConfig']

Oracle session store using async OracleDB driver.

Implements server-side session storage for Litestar using Oracle Database via the async python-oracledb driver. Provides efficient session management with: - Native async Oracle operations - MERGE statement for atomic UPSERT - Automatic expiration handling - Efficient cleanup of expired sessions - Optional In-Memory Column Store support (requires Oracle Database In-Memory license)

OracleADKConfig

Bases: ADKConfig

Oracle ADK extension settings consumed by Oracle ADK stores.

Attributes:

Name Type Description
vector_dimensions NotRequired[int]

Dimensionality of embedding vectors (e.g. 768 for gemini-embedding-001 with MRL). Default: 768.

in_memory NotRequired[bool]

Enable Oracle INMEMORY clauses on ADK tables.

compression NotRequired[OracleADKCompressionConfig]

Oracle ADK table compression settings.

partitioning NotRequired[OracleADKPartitionConfig]

Oracle ADK table partitioning settings.

session_table_options NotRequired[str]

Raw Oracle table options for the ADK session table.

events_table_options NotRequired[str]

Raw Oracle table options for the ADK events table.

app_state_table_options NotRequired[str]

Raw Oracle table options for the ADK app state table.

user_state_table_options NotRequired[str]

Raw Oracle table options for the ADK user state table.

memory_table_options NotRequired[str]

Raw Oracle table options for the ADK memory table.

OracleSyncADKStore

Bases: BaseSyncADKStore['OracleSyncConfig']

Oracle synchronous ADK store using oracledb sync driver.

Implements session and event storage for Google Agent Development Kit using Oracle Database via the python-oracledb synchronous driver. Provides: - Session state management with version-specific JSON storage - Full-fidelity event storage via event_data column - Atomic create_event_and_update_state for durable session mutations - TIMESTAMP WITH TIME ZONE for timezone-aware timestamps - Foreign key constraints with cascade delete - Efficient upserts using MERGE statement

Notes
  • JSON storage type detected by capability (native JSON, BLOB IS JSON, or plain LOB)
  • event_data stored as JSON (21c+) or BLOB (older versions)
  • TIMESTAMP WITH TIME ZONE for timezone-aware timestamps
  • Named parameters using :param_name
  • State merging handled at application level
  • owner_id_column supports NUMBER, VARCHAR2, RAW for Oracle FK types
  • Configuration is read from config.extension_config["adk"]

OracleAsyncADKStore

Bases: BaseAsyncADKStore['OracleAsyncConfig']

Oracle async ADK store using oracledb async driver.

Implements session and event storage for Google Agent Development Kit using Oracle Database via the python-oracledb async driver. Provides: - Session state management with version-specific JSON storage - Full-fidelity event storage via event_data column - Atomic append_event_and_update_state for durable session mutations - TIMESTAMP WITH TIME ZONE for timezone-aware timestamps - Foreign key constraints with cascade delete - Efficient upserts using MERGE statement

Notes
  • JSON storage type detected by capability (native JSON, BLOB IS JSON, or plain LOB)
  • event_data stored as JSON (21c+) or BLOB (older versions)
  • TIMESTAMP WITH TIME ZONE for timezone-aware timestamps
  • Named parameters using :param_name
  • State merging handled at application level
  • owner_id_column supports NUMBER, VARCHAR2, RAW for Oracle FK types
  • Configuration is read from config.extension_config["adk"]

OracleSyncADKMemoryStore

Bases: BaseSyncADKMemoryStore['OracleSyncConfig']

Oracle ADK memory store using sync oracledb driver.

OracleAsyncADKMemoryStore

Bases: BaseAsyncADKMemoryStore['OracleAsyncConfig']

Oracle ADK memory store using async oracledb driver.

OracleEventsConfig

Bases: EventsConfig

Oracle events settings for queue storage and supported native transports.

Attributes:

Name Type Description
in_memory NotRequired[bool]

Emit Oracle INMEMORY PRIORITY HIGH. Default: False.

partitioning NotRequired[OracleEventsPartitionConfig]

Oracle hash/range queue partition settings; omitted for an unpartitioned table.

compression NotRequired[OracleEventsCompressionConfig]

Oracle queue-table compression; disabled unless explicitly enabled.

table_options NotRequired[str]

Additional Oracle queue-table DDL options; omitted by default.

json_storage NotRequired[Literal['json', 'blob_json', 'blob_plain']]

Override Oracle JSON storage detection with json, blob_json or blob_plain.

aq_queue NotRequired[str]

Oracle AQ queue name or channel template. Default: SQLSPEC_EVENTS_QUEUE.

aq_channels NotRequired[list[str]]

Channels reconcile provisions for a {channel} aq_queue template; never restricts runtime publish or dequeue.

aq_visibility NotRequired[int | Literal['DEQ_IMMEDIATE', 'DEQ_ON_COMMIT']]

Oracle AQ visibility integer or DEQ_IMMEDIATE/DEQ_ON_COMMIT name.

aq_wait_seconds NotRequired[int]

Oracle AQ dequeue wait in seconds. Default: 5.

OracleSyncEventQueueStore

Bases: BaseEventQueueStore['OracleSyncConfig']

Oracle sync event queue store with auto-detected JSON storage.

Automatically detects the Oracle version and uses the optimal JSON storage: - Oracle 21c+: Native JSON type - Oracle 12c-19c: BLOB with IS JSON constraint - Oracle 11g: Plain BLOB

OracleAsyncEventQueueStore

Bases: BaseEventQueueStore['OracleAsyncConfig']

Oracle async event queue store with auto-detected JSON storage.

Automatically detects the Oracle version and uses the optimal JSON storage: - Oracle 21c+: Native JSON type - Oracle 12c-19c: BLOB with IS JSON constraint - Oracle 11g: Plain BLOB

OracleSyncAQEventBackend

Oracle AQ backend for sync Oracle adapters.

OracleAsyncAQEventBackend

Oracle AQ backend for async Oracle adapters.

OracleSyncTxEventQEventBackend

Bases: OracleSyncAQEventBackend

Oracle Transactional Event Queues backend for sync Oracle adapters.

Shares the classic AQ client path (queue/enqueue/dequeue); only provisioning (DBMS_AQADM.CREATE_TRANSACTIONAL_EVENT_QUEUE) and the backend label differ.

OracleAsyncTxEventQEventBackend

Bases: OracleAsyncAQEventBackend

Oracle Transactional Event Queues backend for async Oracle adapters.

OracleAcquireOptions

Normalized Oracle checkout overrides with stable equality and hash semantics.

OracleAsyncClientContextStrategy

Bind tenant attributes through asynchronous CLIENTCONTEXT piggybacking.

OracleAsyncEndUserSecurityStrategy

Bind captured tenant identity to a native Deep Data Security context.

OracleAsyncSessionlessTransactionContext

Begin or resume a transaction and suspend it when its request scope exits.

OracleEndUserSecurityConfig

Explicit per-session Oracle Deep Data Security credentials.

OraclePluginName

OraclePluginName = Literal[
    "oci_config_provider",
    "aws_config_provider",
    "azure_config_provider",
    "gcp_config_provider",
    "oci_tokens",
    "azure_tokens",
]

OraclePoolBoundary

OraclePoolBoundary = Literal['statement', 'transaction']

OraclePurityInput

OraclePurityInput = Purity | Literal['DEFAULT', 'NEW', 'SELF'] | int

OracleShardResolver

OracleShardResolver = Callable[
    [TenantContextPayload], tuple[Sequence[Any] | None, Sequence[Any] | None]
]

OracleSyncClientContextStrategy

Bind tenant attributes through the zero-round-trip CLIENTCONTEXT API.

OracleSyncEndUserSecurityStrategy

Bind captured tenant identity to a native Deep Data Security context.

OracleSyncSessionlessTransactionContext

Begin or resume a transaction and suspend it when its request scope exits.

OracleTransactionPriority

OracleTransactionPriority = Literal['DEFAULT', 'LOW', 'MEDIUM', 'HIGH']