Skip to content

sybase Adapter

from sqlspec.adapters.sybase import (
    SybaseConfig,
    SybaseConnectionParams,
    SybaseConnectionPool,
    SybaseDriver,
    SybaseDriverFeatures,
    SybaseExceptionHandler,
    SybasePoolParams,
    SybaseSyncDataDictionary,
    SybaseSyncMigrationTracker,
)

Synchronous SAP Adaptive Server Enterprise (Sybase ASE) 16.0+ adapter built on pymssql over FreeTDS TDS 5.0 wire protocol. Inherited execution methods are documented on SyncDriverAdapterBase. See the Sybase ASE Setup Guide for TDS 5.0 protocol negotiation and connection pooling, and the Sybase Data Dictionary & SQL Catalog for system catalog introspection queries.

Configuration & Parameters

SybaseConfig

SybaseConfig(
    *,
    connection_config: SybasePoolParams | dict[str, Any] | None = None,
    connection_instance: SybaseConnectionPool | None = None,
    migration_config: dict[str, Any] | None = None,
    statement_config: StatementConfig | None = None,
    driver_features: SybaseDriverFeatures | dict[str, Any] | None = None,
    bind_key: str | None = None,
    extension_config: ExtensionConfigs | None = None,
    observability_config: ObservabilityConfig | None = None,
    **kwargs: Any,
)

Bases: SyncDatabaseConfig[SybaseConnection, SybaseConnectionPool, SybaseDriver]

Configuration for Sybase ASE synchronous connections over pymssql (FreeTDS TDS 5.0).

Methods:

Name Description
create_connection

Open a standalone Sybase ASE connection owned by the caller.

get_signature_namespace
get_event_runtime_hints

Return runtime hints for Sybase ASE event channels.

Attributes:

Name Type Description
driver_type type[SybaseDriver]
connection_type type[SybaseConnection]
migration_tracker_type type[SybaseSyncMigrationTracker]
supports_transactional_ddl bool
supports_migration_schemas bool
supports_native_arrow_export bool
supports_native_arrow_import bool
supports_native_parquet_export bool
supports_native_parquet_import bool
supports_native_row_streaming bool
type_coercion_capabilities TypeCoercionCapabilities

create_connection

create_connection() -> SybaseConnection

Open a standalone Sybase ASE connection owned by the caller.

get_signature_namespace

get_signature_namespace() -> dict[str, Any]

get_event_runtime_hints

get_event_runtime_hints() -> EventRuntimeHints

Return runtime hints for Sybase ASE event channels.

SybaseConnectionParams

Bases: TypedDict

Sybase ASE connection parameters.

Attributes:

Name Type Description
server NotRequired[str]

Database server host, IP, or FreeTDS server definition name.

host NotRequired[str]

Alias for server.

freetds_server NotRequired[str]

FreeTDS server configuration section name.

server_alias NotRequired[str]

Alias for server.

user NotRequired[str]

Login user name.

username NotRequired[str]

Alias for user.

password NotRequired[str]

Authentication password.

database NotRequired[str]

Initial database name to connect to.

db NotRequired[str]

Alias for database.

port NotRequired[int | str]

TCP port number of the Sybase ASE server.

timeout NotRequired[SybaseTimeout]

Query execution timeout in seconds.

login_timeout NotRequired[SybaseTimeout]

Login and connection timeout in seconds.

charset NotRequired[str]

Client character set encoding.

as_dict NotRequired[bool]

Return query result rows as dictionaries.

appname NotRequired[str]

Application name sent to the server for connection identification.

conn_properties NotRequired[str]

Additional connection properties string.

autocommit NotRequired[bool]

Enable autocommit mode for transactions.

tds_version NotRequired[str]

TDS protocol version (such as '5.0' or '7.4').

encryption NotRequired[Literal['off', 'request', 'require']]

TDS connection encryption level.

arraysize NotRequired[int]

Default cursor fetch array size.

conv NotRequired[Mapping[int | type[Any], Callable[..., Any]]]

Custom datatype conversion dictionary mapping TDS types to python types.

read_only NotRequired[bool]

Enforce read-only transactions on connections.

pool_recycle_seconds NotRequired[int]

Maximum age in seconds before a pooled connection is recycled.

health_check_interval NotRequired[float]

Interval in seconds between background health checks.

extra NotRequired[dict[str, Any]]

Additional driver connection arguments.

SybasePoolParams

Bases: SybaseConnectionParams

Sybase ASE pool parameters.

SybaseDriverFeatures

Bases: TypedDict

Sybase ASE driver feature flags.

Attributes:

Name Type Description
json_serializer NotRequired[Callable[[Any], str]]

Custom callable for serializing objects to JSON strings.

json_deserializer NotRequired[Callable[[str], Any]]

Custom callable for deserializing JSON strings.

on_connection_create NotRequired[Callable[[SybaseConnection], None]]

Callback invoked immediately when a new connection is established.

enable_events NotRequired[bool]

Enable database event listening.

events_backend NotRequired[Literal['poll_queue']]

Backend mechanism used for dispatching events.

Driver, Pool & Data Dictionary

SybaseDriver

SybaseDriver(
    connection: SybaseConnection,
    statement_config: StatementConfig | None = None,
    driver_features: dict[str, Any] | None = None,
)

Bases: SyncDriverAdapterBase

Sybase Adaptive Server Enterprise database driver using pymssql over FreeTDS TDS 5.0.

Attributes:

Name Type Description
dialect
data_dictionary SybaseSyncDataDictionary

SybaseExceptionHandler

SybaseExceptionHandler()

Bases: BaseSyncExceptionHandler

Context manager for handling Sybase pymssql exceptions.

SybaseConnectionPool

SybaseConnectionPool(
    connection_parameters: dict[str, Any],
    recycle_seconds: int = 86400,
    health_check_interval: float = 30.0,
    on_connection_create: Callable[[SybaseConnection], None] | None = None,
)

Thread-local connection manager for Sybase ASE over pymssql (FreeTDS TDS 5.0).

Initialize the thread-local Sybase ASE connection manager.

Parameters:

Name Type Description Default
connection_parameters dict[str, Any]

Normalized Sybase connection parameters.

required
recycle_seconds int

Connection recycle time in seconds (default 24h).

86400
health_check_interval float

Seconds of idle time before running health check.

30.0
on_connection_create Callable[[SybaseConnection], None] | None

Callback executed when a connection is created.

None

Methods:

Name Description
new_connection

Open a standalone Sybase ASE connection using FreeTDS TDS 5.0 negotiation.

get_connection

Get a thread-local connection.

close

Close every connection this pool opened, on any thread.

acquire
release
size
checked_out

new_connection

new_connection() -> SybaseConnection

Open a standalone Sybase ASE connection using FreeTDS TDS 5.0 negotiation.

Returns:

Name Type Description
SybaseConnection SybaseConnection

A newly opened, fully configured connection.

get_connection

get_connection() -> Generator[SybaseConnection, None, None]

Get a thread-local connection.

Yields:

Type Description
SybaseConnection

A thread-local database connection.

close

close() -> None

Close every connection this pool opened, on any thread.

acquire

acquire() -> SybaseConnection

release

release(connection: SybaseConnection) -> None

size

size() -> int

checked_out

checked_out() -> int

SybaseSyncDataDictionary

SybaseSyncDataDictionary()

Bases: SyncDataDictionaryBase

Sybase ASE sync data dictionary for metadata reflection.

Initialize Sybase ASE sync data dictionary.

Attributes:

Name Type Description
dialect str

SybaseSyncMigrationTracker

SybaseSyncMigrationTracker(
    version_table_name: str = "ddl_migrations",
    version_table_schema: str | None = None,
)

Bases: SybaseMigrationTrackerMixin, SyncMigrationTracker

Sybase ASE sync migration tracker.

Extension Stores & Configs

SybaseStore

SybaseStore(config: SybaseConfig)

Bases: BaseSQLSpecStore['SybaseConfig']

Sybase ASE-backed session store using pymssql sync sessions.

Methods:

Name Description
create_table

Create the session table if it doesn't exist.

get

Get a session value by key.

set

Store a session value.

delete

Delete a session by key.

delete_all

Delete all sessions from the store.

exists

Check if a session key exists and is not expired.

expires_in

Get the time in seconds until the session expires.

delete_expired

Delete all expired sessions.

create_table async
create_table() -> None

Create the session table if it doesn't exist.

get async
get(key: str, renew_for: int | timedelta | None = None) -> bytes | None

Get a session value by key.

set async
set(
    key: str, value: str | bytes, expires_in: int | timedelta | None = None
) -> None

Store a session value.

delete async
delete(key: str) -> None

Delete a session by key.

delete_all async
delete_all() -> None

Delete all sessions from the store.

exists async
exists(key: str) -> bool

Check if a session key exists and is not expired.

expires_in async
expires_in(key: str) -> int | None

Get the time in seconds until the session expires.

delete_expired async
delete_expired() -> int

Delete all expired sessions.

SybaseADKConfig

Bases: ADKConfig

Sybase ASE ADK extension settings.

SybaseADKStore

SybaseADKStore(config: SybaseConfig)

Bases: BaseSyncADKStore['SybaseConfig']

Synchronous Sybase ASE ADK session/event store.

Methods:

Name Description
create_tables

Create ADK tables (idempotent Sybase ASE DDL) and DD-gated indexes.

create_session

Create a new ADK session.

get_session

Return a scoped session or None if absent.

update_session_state

Replace a session's durable state.

list_sessions

List ADK sessions for an application, optionally scoped to a user.

delete_session

Delete a session and its associated events.

append_event

Append an event to a session.

append_event_and_update_state

Atomically append an event and update durable session/scoped state.

get_events

Return events for a scoped session ordered by event timestamp.

delete_expired_events

Delete events older than before.

delete_idle_sessions

Delete sessions whose update_time is older than updated_before.

delete_idle_user_states

Delete user state rows whose update_time is older than updated_before.

get_app_state

Return app-scoped state.

get_user_state

Return user-scoped state.

upsert_app_state

Insert or replace app-scoped state.

upsert_user_state

Insert or replace user-scoped state.

get_metadata

Return an ADK metadata value.

set_metadata

Set an ADK metadata value.

Attributes:

Name Type Description
connector_name str
create_tables
create_tables() -> None

Create ADK tables (idempotent Sybase ASE DDL) and DD-gated indexes.

create_session
create_session(
    session_id: str,
    app_name: str,
    user_id: str,
    state: dict[str, Any],
    owner_id: Any | None = None,
) -> StoredSession

Create a new ADK session.

get_session
get_session(
    app_name: str,
    user_id: str,
    session_id: str,
    *,
    renew_for: int | timedelta | None = None,
) -> StoredSession | None

Return a scoped session or None if absent.

update_session_state
update_session_state(
    app_name: str, user_id: str, session_id: str, state: dict[str, Any]
) -> None

Replace a session's durable state.

list_sessions
list_sessions(
    app_name: str,
    user_id: str | None = None,
    *,
    order_by: SessionOrderBy = "update_time",
    descending: bool = True,
    limit: int | None = None,
    offset: int | None = None,
) -> list[StoredSession]

List ADK sessions for an application, optionally scoped to a user.

delete_session
delete_session(app_name: str, user_id: str, session_id: str) -> None

Delete a session and its associated events.

append_event
append_event(event_record: StoredEvent) -> None

Append an event to a session.

append_event_and_update_state
append_event_and_update_state(
    event_record: StoredEvent,
    app_name: str,
    user_id: str,
    session_id: str,
    state: dict[str, Any],
    *,
    app_state: dict[str, Any] | None = None,
    user_state: dict[str, Any] | None = None,
) -> StoredSession

Atomically append an event and update durable session/scoped state.

get_events
get_events(
    app_name: str,
    user_id: str,
    session_id: str,
    after_timestamp: datetime | None = None,
    limit: int | None = None,
) -> list[StoredEvent]

Return events for a scoped session ordered by event timestamp.

delete_expired_events
delete_expired_events(before: datetime, app_name: str | None = None) -> int

Delete events older than before.

delete_idle_sessions
delete_idle_sessions(
    updated_before: datetime, app_name: str | None = None
) -> int

Delete sessions whose update_time is older than updated_before.

delete_idle_user_states
delete_idle_user_states(
    updated_before: datetime, app_name: str | None = None
) -> int

Delete user state rows whose update_time is older than updated_before.

get_app_state
get_app_state(app_name: str) -> dict[str, Any] | None

Return app-scoped state.

get_user_state
get_user_state(app_name: str, user_id: str) -> dict[str, Any] | None

Return user-scoped state.

upsert_app_state
upsert_app_state(app_name: str, state: dict[str, Any]) -> None

Insert or replace app-scoped state.

upsert_user_state
upsert_user_state(app_name: str, user_id: str, state: dict[str, Any]) -> None

Insert or replace user-scoped state.

get_metadata
get_metadata(key: str) -> str | None

Return an ADK metadata value.

set_metadata
set_metadata(key: str, value: str) -> None

Set an ADK metadata value.

SybaseADKMemoryStore

SybaseADKMemoryStore(config: SybaseConfig)

Bases: BaseSyncADKMemoryStore['SybaseConfig']

Sybase ASE ADK memory store using pymssql.

Methods:

Name Description
create_tables

Create the memory table (idempotent Sybase ASE DDL) and DD-gated indexes.

insert_memory_entries

Bulk insert memory entries with event-id deduplication.

search_entries

Search memory entries by text query.

delete_entries_by_session

Delete all memory entries for a specific session.

delete_entries_older_than

Delete memory entries older than the retention window.

create_tables
create_tables() -> None

Create the memory table (idempotent Sybase ASE DDL) and DD-gated indexes.

insert_memory_entries
insert_memory_entries(
    entries: list[StoredMemory], owner_id: object | None = None
) -> int

Bulk insert memory entries with event-id deduplication.

search_entries
search_entries(
    query: str,
    app_name: str,
    user_id: str,
    limit: int | None = None,
    scope_filter: Literal["all", "user", "app"] = "all",
    embedding: Sequence[float] | None = None,
) -> list[StoredMemory]

Search memory entries by text query.

delete_entries_by_session
delete_entries_by_session(session_id: str) -> int

Delete all memory entries for a specific session.

delete_entries_older_than
delete_entries_older_than(
    days: int, app_name: str | None = None, scope: str | None = None
) -> int

Delete memory entries older than the retention window.

SybaseSyncEventQueueStore

SybaseSyncEventQueueStore(config: ConfigT)

Bases: BaseEventQueueStore[SybaseConfig]

Sybase ASE DDL hooks for the event queue store.