Skip to content

Converters

See Custom conversions for how conv= is used.

Conversions between Python values and SQL.

Parameters are interpolated into the query text (paramstyle = "format"), which is what SQLAlchemy's MySQL dialects expect. The work happens in the native module; escape_string, literal and interpolate are thin wrappers for direct use and tests.

conversions is the default conv= mapping, in MySQLdb's format: column types (FIELD_TYPE) to decoders and Python types to encoders. Passing it, or a copy with a few entries changed, keeps every other column on the native fast path: only entries that differ from it are called from Python.

conversions module-attribute

conversions: dict[Any, Any] = {**encoders, **decoders}

Default conv= mapping (MySQLdb format).

escape_string

escape_string(value: str, *, no_backslash_escapes: bool = False) -> str

Escape value for use inside a single-quoted SQL string.

literal

literal(value: object, *, no_backslash_escapes: bool = False) -> str

Render value as an SQL literal (UTF-8 connection).

split_conv

split_conv(
    conv: Mapping[Any, Any],
) -> tuple[dict[int, Any] | None, dict[type, Encoder] | None]

The decoders and encoders of conv that differ from the defaults, None when there are none.