Documentation
Documentation
sqlc-gen-better-python is a sqlc plugin that turns your SQL
schema and queries into modern, fully typed Python database code: models, typed
query functions, and enums. You keep writing SQL; the Python stays in sync with
it.
Install the plugin and go from a schema to your first typed queries.
Every feature, explained with real schema, queries, and generated output.
Configuration options, type mappings, and per-driver support.
Explore by feature
asyncpg, psycopg, aiosqlite, and sqlite3.
dataclass, attrs, msgspec, or pydantic.
How query annotations become typed functions.
PostgreSQL enums as enum.StrEnum classes.
Swap the Python type of a column.
Your own encode/decode functions for a column.
Typed JSON columns with msgspec structs.
google, numpy, or pep257 docstrings.
At a glance
| Python | 3.12 or newer |
| Engines | PostgreSQL, SQLite |
| Drivers | asyncpg, psycopg_async, aiosqlite, sqlite3 |
| Model types | dataclass, attrs, msgspec, pydantic |
| Docstrings | google, numpy, pep257, or none |
| Checked with | pyright (strict) and ruff |
Full details in the feature support reference.