pymysql Adapter¶
from sqlspec.adapters.pymysql import (
PyMysqlConfig,
PyMysqlConnectionParams,
PyMysqlDriver,
PyMysqlDriverFeatures,
PyMysqlExceptionHandler,
PyMysqlPoolParams,
)
Synchronous MySQL and MariaDB adapter built on pymysql. Inherited execution methods are documented on SyncDriverAdapterBase. See the MySQL & MariaDB Setup Guide for usage examples.
Configuration & Parameters¶
PyMysqlConfig
¶
Bases: SyncDatabaseConfig[PyMysqlConnection, PyMysqlConnectionPool, PyMysqlDriver]
Configuration for PyMySQL synchronous connections.
PyMysqlConnectionParams
¶
Bases: TypedDict
PyMySQL 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 |
collation |
NotRequired[str]
|
Session collation paired with |
sql_mode |
NotRequired[str]
|
Session |
read_default_file |
NotRequired[str]
|
Path to a MySQL |
read_default_group |
NotRequired[str]
|
Option group name read from |
conv |
NotRequired[PyMysqlConverter]
|
Custom PyMySQL type encoder/decoder mapping. |
use_unicode |
NotRequired[bool]
|
Decode text columns into Python |
client_flag |
NotRequired[int]
|
Bitmask of MySQL |
cursorclass |
NotRequired[type[PyMysqlRawCursor]]
|
Default PyMySQL cursor class instantiated by |
init_command |
NotRequired[str]
|
SQL statement executed immediately after authentication. |
connect_timeout |
NotRequired[PyMysqlTimeout]
|
TCP handshake and authentication timeout in seconds. |
read_timeout |
NotRequired[PyMysqlTimeout]
|
Socket read timeout in seconds for server responses. |
write_timeout |
NotRequired[PyMysqlTimeout]
|
Socket write timeout in seconds for outgoing packets. |
autocommit |
NotRequired[bool]
|
Enable MySQL autocommit mode on new connections. |
allow_local_infile |
NotRequired[bool]
|
Alias enabling |
local_infile |
NotRequired[bool]
|
Permit client-side |
max_allowed_packet |
NotRequired[int]
|
Maximum client packet size in bytes. |
defer_connect |
NotRequired[bool]
|
Construct the |
auth_plugin_map |
NotRequired[Mapping[str, type[Any]]]
|
Mapping from MySQL auth plugin names to custom handler classes. |
bind_address |
NotRequired[str]
|
Local source IP address or hostname bound by the client socket. |
binary_prefix |
NotRequired[bool]
|
Emit |
program_name |
NotRequired[str]
|
Application name sent in MySQL connection attributes. |
server_public_key |
NotRequired[str | bytes]
|
Server RSA public key PEM used for SHA-256 password exchange. |
ssl |
NotRequired[PyMysqlSslConfig]
|
TLS |
ssl_ca |
NotRequired[str]
|
Path to the PEM CA bundle file for TLS verification. |
ssl_cert |
NotRequired[str]
|
Path to the client TLS certificate file. |
ssl_disabled |
NotRequired[bool]
|
Disable TLS negotiation completely when |
ssl_key |
NotRequired[str]
|
Path to the client TLS private key file. |
ssl_key_password |
NotRequired[str]
|
Passphrase unlocking an encrypted |
ssl_verify_cert |
NotRequired[bool]
|
Verify the server TLS certificate against |
ssl_verify_identity |
NotRequired[bool]
|
Verify that the server TLS certificate matches the target hostname. |
extra |
NotRequired[dict[str, Any]]
|
Additional keyword arguments forwarded to |
PyMysqlPoolParams
¶
Bases: PyMysqlConnectionParams
PyMySQL pool parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
pool_recycle_seconds |
NotRequired[int]
|
Maximum connection age in seconds before recycling pooled PyMySQL connections. |
health_check_interval |
NotRequired[float]
|
Minimum interval in seconds between |
PyMysqlDriverFeatures
¶
Bases: TypedDict
Optional PyMySQL driver feature flags, Cloud SQL connector settings, and bulk-load options.
Attributes:
| Name | Type | Description |
|---|---|---|
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[[PyMysqlConnection], None]]
|
Synchronous hook invoked with each raw |
enable_events |
NotRequired[bool]
|
Enable durable table-backed SQLSpec event queue support. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Event channel backend ( |
enable_local_infile_bulk_load |
NotRequired[bool]
|
Route |
enable_cloud_sql |
NotRequired[bool]
|
Route connections through |
cloud_sql_instance |
NotRequired[str]
|
Cloud SQL instance connection string in |
cloud_sql_enable_iam_auth |
NotRequired[bool]
|
Use IAM database authentication with the Cloud SQL Python Connector. |
cloud_sql_ip_type |
NotRequired[str]
|
Cloud SQL network path ( |