rayakame/sqlc-gen-better-python
rayakame/sqlc-gen-better-python has 43 GitHub stars and 5 forks. GitHot measured 0 stars in 24 hours. Last checked 2026-11-10 00:03 UTC. Last push 2026-11-03.
A sqlc plugin that generates modern, type-safe Python from SQL
What you can do
- Four model types - dataclass, attrs, msgspec, or pydantic (docs).
- Nine drivers - asyncpg, psycopg_async, and psycopg_sync for PostgreSQL, aiosqlite and sqlite3 for SQLite, asyncmy and pymysql for MySQL, plus experimental turso_async and turso_sync for Turso (docs).
- Typed query functions - one module per query file, one function per query (docs).
- PostgreSQL enum types and MySQL enum columns as enum.StrEnum classes (docs).
Measured star growth
- in 24h
- 0
- in 7 days
- Update delayed
- in 15 days
- Update delayed
- in 1 month
- Update delayed
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
README.md
Originalsqlc-gen-better-python
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.
You write:
-- name: GetUser :one
SELECT * FROM users WHERE id = $1;
and get back:
async def get_user(conn: ConnectionLike, *, id_: int) -> models.User | None:
row = await conn.fetchrow(GET_USER, id_)
if row is None:
return None
return models.User(id_=row[0], name=row[1])
No ORM, no hand-written row unpacking. Generated code targets Python 3.12 or newer and passes pyright (strict) and ruff.
Documentation
https://sqlc-gen-better-python.rayakame.dev/
- Getting Started - install the plugin and generate your first models.
- Guide - every feature, each with real generated output.
- Reference - all options, type mappings, and per-driver feature support.
Questions or feedback? Join the Discord.
Features
- Four model types -
dataclass,attrs,msgspec, orpydantic(docs). - Nine drivers -
asyncpg,psycopg_async, andpsycopg_syncfor PostgreSQL,aiosqliteandsqlite3for SQLite,asyncmyandpymysqlfor MySQL, plus experimentalturso_asyncandturso_syncfor Turso (docs). - Typed query functions - one module per query file, one function per query (docs).
- PostgreSQL enum types and MySQL enum columns as
enum.StrEnumclasses (docs). - Type overrides and converters - swap a column's Python type, or plug in your own encode/decode functions (overrides, converters).
- Typed JSON columns via msgspec structs (docs).
- Optional docstrings in
google,numpy, orpep257convention (docs).
Every sqlc macro is supported. Which query commands are available depends on the driver - see the feature support matrix.
Example config
# filename: sqlc.yaml
version: "2"
plugins:
- name: python
wasm:
url: https://github.com/rayakame/sqlc-gen-better-python/releases/download/v0.9.0/sqlc-gen-better-python.wasm
sha256: d1787aa32e61f2e73c81a4f93b3e5a9beeec918952cff3183fb96313057f58a8
sql:
- engine: "postgresql"
queries: "query.sql"
schema: "schema.sql"
codegen:
- out: "app/db"
plugin: python
options:
package: "db"
emit_init_file: true
sql_driver: "asyncpg"
model_type: "msgspec"
[!TIP] No
sqlcyet? Besides the official installation methods,uv add --dev sqlc-bin(orpip install sqlc-bin) installssqlc-bin, the unmodified official binaries as a pinnable Python package - no Go toolchain required.
More options at the sqlc config reference,
and the full plugin option list in the
configuration reference.
Used by
nMarkov - a Discord chatbot that learns from your server's messages and generates its own.
Using sqlc-gen-better-python in your project? Open an issue
to get listed here.
Development
Contributions are very welcome, for more information and help please read the contribution guidelines.
Changelog
Can be found here
Credits
Special thanks to tandemdude for answering my questions on discord.
Explore related projects
Asabeneh/30-Days-Of-Python
The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,486 starsgrafana/grafana
The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
77,790 starsredis/redis
For developers, who are building real-time data-driven applications, Redis is the preferred, fastest, and most feature-rich cache, data structure server, and document and vector query engine.
77,332 starsapache/superset
Apache Superset is a Data Visualization and Data Exploration Platform
75,455 stars