Typed SQL for Python¶
Write SQL-shaped queries in Python, with editor checks for column names, filter values, and selected result types. Pysely is async-first and inspired by Kysely.
Early development
Pysely is not production-ready. The API can change while the core query surface is completed.
rows = await (
db.select_from("person")
.select("id")
.select("first_name")
.where("first_name", "=", "Jennifer")
.execute()
)
Types without generated runtime code¶
Write your schema in dbschema.py. Run pysely typgen dbschema.py to generate
dbschema.pyi for mypy and Pyright.
Python never loads the stub. Your app uses the handwritten schema and shared library code—no massive generated runtime file and no checker plugin.
Pick a starting point¶
- Run your first query with a complete SQLite example.
- Browse the query APIs for joins, filters, and transactions.
- Understand typing and its current limits.
- Try the playground without installing anything.
Current database support¶
| Database | Compiler | Async execution |
|---|---|---|
| PostgreSQL | Yes | asyncpg |
| MySQL | Yes | asyncmy |
| SQLite | Yes | aiosqlite |
MSSQL and PGlite runtime adapters are deferred until the primary dialects meet the production-readiness gates.