aiosql allows you to write SQL queries in separate .sql files and call them directly from Python as async or sync functions. It supports multiple database drivers (sqlite3, aiosqlite, psycopg2, asyncpg, etc.) and provides a clean separation of SQL and Python. Current version 15.0, requires Python ≥3.10. Release cadence is irregular but actively maintained.
pip install aiosqlVerified import paths — ran on the pinned version, not inferred.
Load SQL queries from a directory and call them as Python functions.
Change to `aiosql.from_path('queries', 'sqlite3')` or pass the module object: `aiosql.from_path('queries', aiosql.adapters.sqlite)`.Ensure each SQL file has unique `-- name:` tags. Use a single directory or namespace with subdirectories.
Replace `aiosql.from_sql(...)` with `aiosql.from_str(...)` or `aiosql.from_path(...)`.
pip install aiosql
Check that the SQL file contains `-- name: get_user` (case-sensitive, exact match) and that the file is in the directory passed to `from_path`.
Use `aiosql.from_path('queries', 'sqlite3')` or `aiosql.from_path('queries', driver_name='sqlite3')`.No dependency data recorded yet.