aiosql
Simple SQL in Python
What it is and what it does
aiosql lets you organize SQL queries in separate .sql files and load them into Python as callable methods, rather than embedding SQL as strings in your code. This approach keeps your SQL reusable—you can run the same queries in psql or other database tools without modification—while maintaining clean separation between SQL and Python logic.
The package works with both synchronous PEP 249 drivers (sqlite3, psycopg2, PyMySQL, etc.) and asyncio-based drivers (aiosqlite, asyncpg, asyncmy, etc.). You write parametric SQL with named parameters, load the file via aiosql.from_path(), and call queries by name, passing a connection object and any required parameters. It's a lightweight alternative to ORMs when you want to write and maintain SQL directly.
Use it for:
- Organize complex SQL queries in version-controlled .sql files for a Python application using SQLite or PostgreSQL
- Run the same parameterized SQL queries from both Python code and command-line tools like psql without duplication
- Build async applications that execute multiple SQL queries concurrently using aiosqlite or asyncpg
- Maintain SQL code separately from Python when you prefer hand-written queries over ORM-generated SQL
- Support multiple database backends (SQLite, PostgreSQL, MySQL, DuckDB) with a single query file and driver parameter
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Load SQL queries from files and call them as Python methods, supporting both sync and async database drivers across SQLite, PostgreSQL, MySQL, MariaDB, DuckDB, and MS SQL Server.
Yes. aiosql is actively maintained, has no runtime dependencies, requires only Python >=3.10, and carries no known vulnerabilities. It's worth installing if you want to keep SQL in files and call it from Python without an ORM, and you're comfortable writing SQL directly. Skip it if you need an ORM or prefer SQL-like syntax in Python.
Install
aiosql on PyPI
pip
pip install aiosqluv
uv add aiosqlpoetry
poetry add aiosqlInstalling aiosql
Before you install
Low friction install with no runtime dependencies. Active maintenance with last commit 2026-07-10 and 1409 repository stars. Requires Python >=3.10.
License in practice
BSD-2-Clause permissive license allows commercial and private use with minimal restrictions.
Quickstart
pip install aiosql
import aiosql
import sqlite3
queries = aiosql.from_path("greetings.sql", "sqlite3")
with sqlite3.connect("greetings.db") as conn:
user = queries.get_user_by_username(conn, username="willvaughn")
Requires Python >=3.10 and a compatible database driver (sqlite3, psycopg, asyncpg, etc.) installed separately.
Verify before relying
- Whether all listed database drivers work equally well or if some have known limitations beyond what the description states
- Performance characteristics when loading and executing many queries from a single SQL file
Package facts
| License | BSD-2-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 222 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 162,590/month — #10,595 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aiosql-15.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI
aiosqliteaiosqlite provides an async interface to SQLite…
permissive · top 1,000 on PyPI
asyncmyasyncmy is an asyncio-native MySQL/MariaDB…
permissive · top 5,000 on PyPI
aiomysqlaiomysql provides async/await access to MySQL…
permissive · top 5,000 on PyPI
apswAPSW is a Python wrapper around SQLite's…
unclear · top 5,000 on PyPI
apswutilsProvides a Python interface for SQLite…
permissive · top 15,000 on PyPI
pysqlsyncSynchronize database schemas and bulk-load data…
permissive · top 15,000 on PyPI
asyncmy2asyncmy2 is a fast asyncio-based MySQL/MariaDB…
permissive · top 15,000 on PyPI
hopsworks-aiomysqlAsync MySQL database driver for Python asyncio…
permissive · top 15,000 on PyPI
duckdbDuckDB is an in-process SQL database engine…
permissive · top 1,000 on PyPI