skillfed

aiosql

Simple SQL in Python

aiosql v15.0 162.6K downloads/30d#10,595 on PyPI1,409
Permissive license BSD-2-Clause Active released

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 aiosql

uv

uv add aiosql

poetry

poetry add aiosql

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: SQLTopic :: DatabaseTopic :: Software Development :: Libraries :: Python Modules

Tags

SQL queries from filesexternal SQL file loaderyesql pythonSQL file managementdatabase query organizationsync async SQL driverparametric SQL execution
sql-file-loaderasync-database

More Python Modules packages