asyncmy Adapter¶
from sqlspec.adapters.asyncmy import (
AsyncmyConfig,
AsyncmyConnectionParams,
AsyncmyDriver,
AsyncmyDriverFeatures,
AsyncmyExceptionHandler,
AsyncmyPoolParams,
)
Asynchronous MySQL and MariaDB adapter built on asyncmy. Inherited execution methods are documented on AsyncDriverAdapterBase. See the MySQL & MariaDB Setup Guide for usage examples.
Configuration & Parameters¶
AsyncmyConfig
¶
Bases: AsyncDatabaseConfig[AsyncmyConnection, 'AsyncmyPool', AsyncmyDriver]
Configuration for Asyncmy database connections.
AsyncmyConnectionParams
¶
Bases: TypedDict
Asyncmy connection parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
dsn |
NotRequired[str]
|
MySQL/MariaDB connection URI ( |
url |
NotRequired[str]
|
Connection URL alias parsed identically to |
connection_string |
NotRequired[str]
|
Connection string alias parsed identically to |
host |
NotRequired[str]
|
MySQL or MariaDB server hostname (defaults to |
user |
NotRequired[str]
|
Database account username. |
username |
NotRequired[str]
|
Alias normalized to |
password |
NotRequired[str]
|
Password for the database user. |
database |
NotRequired[str]
|
Default schema/database selected upon connecting. |
db |
NotRequired[str]
|
Alias for |
port |
NotRequired[int]
|
MySQL/MariaDB TCP port (defaults to |
unix_socket |
NotRequired[str]
|
Filesystem path to a local MySQL Unix domain socket. |
charset |
NotRequired[str]
|
Connection character set (defaults to |
connect_timeout |
NotRequired[int | float]
|
TCP handshake and authentication timeout in seconds. |
read_default_file |
NotRequired[str]
|
Path to a MySQL |
read_default_group |
NotRequired[str]
|
Option group name read from |
autocommit |
NotRequired[bool]
|
Enable MySQL autocommit mode on new connections. |
allow_local_infile |
NotRequired[bool]
|
Permit client-side |
local_infile |
NotRequired[bool]
|
Alias enabling |
ssl |
NotRequired[AsyncmySSLParams | SSLContext | dict[str, Any]]
|
TLS configuration mapping or |
sql_mode |
NotRequired[str]
|
Session |
init_command |
NotRequired[str]
|
SQL statement executed immediately after authentication. |
auth_plugin_map |
NotRequired[dict[str | bytes, type[Any]]]
|
Mapping from MySQL auth plugin names to custom handler classes. |
binary_prefix |
NotRequired[bool]
|
Emit |
client_flag |
NotRequired[int]
|
Bitmask of MySQL |
conv |
NotRequired[dict[Any, Any]]
|
Custom MySQL field-type conversion table. |
cursor_class |
NotRequired[type[AsyncmyRawCursor] | type[AsyncmyDictCursor]]
|
Cursor class alias normalized for |
cursor_cls |
NotRequired[type[AsyncmyRawCursor] | type[AsyncmyDictCursor]]
|
Default |
max_allowed_packet |
NotRequired[int]
|
Maximum client packet size in bytes (defaults to |
program_name |
NotRequired[str]
|
Client program name reported in |
read_timeout |
NotRequired[int | float]
|
Socket read timeout in seconds for query responses. |
server_public_key |
NotRequired[str | bytes]
|
RSA public key PEM used for |
stmt_cache_size |
NotRequired[int]
|
Maximum prepared statements cached per |
use_unicode |
NotRequired[bool]
|
Decode string columns into Python |
write_timeout |
NotRequired[int | float]
|
Socket write timeout in seconds for outgoing packets. |
extra |
NotRequired[dict[str, Any]]
|
Additional keyword arguments forwarded to |
AsyncmyPoolParams
¶
Bases: AsyncmyConnectionParams
Asyncmy pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
minsize |
NotRequired[int]
|
Minimum number of open connections maintained in |
maxsize |
NotRequired[int]
|
Maximum number of concurrent connections allowed in |
echo |
NotRequired[bool]
|
Log executed SQL statements on |
pool_recycle |
NotRequired[int]
|
Maximum connection age in seconds before |
AsyncmyDriverFeatures
¶
Bases: TypedDict
Optional Asyncmy driver feature flags for JSON serialization, bulk loading, and events.
Attributes:
| Name | Type | Description |
|---|---|---|
enable_local_infile_bulk_load |
NotRequired[bool]
|
Use |
json_serializer |
NotRequired[Callable[[Any], str]]
|
Custom JSON serializer applied to bound JSON parameters (defaults to |
json_deserializer |
NotRequired[Callable[[str], Any]]
|
Custom JSON deserializer applied to JSON result columns (defaults to |
on_connection_create |
NotRequired[Callable[[AsyncmyConnection], Awaitable[None]]]
|
Async callback invoked once per physical |
enable_events |
NotRequired[bool]
|
Enable durable table-backed SQLSpec event queue support. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Event channel backend ( |
Driver & Pool¶
AsyncmyDriver
¶
Bases: AsyncDriverAdapterBase
MySQL/MariaDB database driver using AsyncMy client library.
Implements asynchronous database operations for MySQL and MariaDB servers with support for parameter style conversion, type coercion, error handling, and transaction management.
AsyncmyExceptionHandler
¶
Bases: BaseAsyncExceptionHandler
Async context manager for handling asyncmy (MySQL) database exceptions.
Maps MySQL error codes and SQLSTATE values to SQLSpec exceptions stored on
pending_exception.
Extension Stores¶
AsyncmyStore
¶
Bases: BaseSQLSpecStore['AsyncmyConfig']
MySQL/MariaDB session store using AsyncMy driver.
Implements server-side session storage for Litestar using MySQL/MariaDB via the AsyncMy driver. Provides efficient session management with: - Native async MySQL operations - UPSERT support using ON DUPLICATE KEY UPDATE - Automatic expiration handling - Efficient cleanup of expired sessions - Timezone-aware expiration (stored as UTC in DATETIME)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AsyncmyConfig
|
AsyncmyConfig instance. |
required |
AsyncmyADKStore
¶
AsyncmyADKMemoryStore
¶
Bases: BaseAsyncADKMemoryStore['AsyncmyConfig']
MySQL/MariaDB ADK memory store using AsyncMy driver.
AsyncmyEventQueueStore
¶
Bases: BaseEventQueueStore[AsyncmyConfig]
MySQL-specific event queue store.
Generates DDL optimized for MySQL 5.7.8+ using native JSON type. Index
creation emits a plain ADD INDEX statement; the migration gates it on a
data_dictionary.get_indexes check since MySQL has no idempotent
CREATE INDEX IF NOT EXISTS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ConfigT
|
AsyncmyConfig with extension_config["events"] settings. |
required |