Simple, async query library for modern Python
aql is a simple, modern, and composable query builder, with support for asynchronous execution of queries against multiple database backends using a unified API. aql uses modern, type annotated data structures for both table definitions and queries.
aql is still in early alpha. Not all features are available or finalized.
Define tables:
@table("objects")
class Object:
id: PrimaryKey[AutoIncrement[int]]
name: Unique[str]
description: text
created: datetime
Build queries:
query = (
Object.select()
.where(Object.id >= 25)
.order_by(Object.name)
.limit(5)
)
sql, params = SqlEngine.prepare(query)
# "select * from `objects` where `id` >= ? order by `name` asc limit 5", (25)
Execute queries:
async with connect(...) as db:
cursor = db.execute(Object.select().where(Object.id < 100))
async for row in cursor:
print(f"{row.id} {row.name} {row.description}")
Simple actions:
async with connect(...) as db:
rows = await db.get(Object, Object.id == 100)
rows[0].description += "updated"
await db.modify(Object, rows)
aql is copyright Amethyst Reese, and licensed under
the MIT license. I am providing code in this repository to you under an open
source license. This is my personal repository; the license you receive to
my code is from me and not from my employer. See the LICENSE
file for details.