Getting started¶
Installation¶
Install the core library plus all optional integrations in one shot:
pip install "alchemiq[all]"
Or pick only what your project needs. The core package ships no database
driver, so for PostgreSQL start from the postgres extra - it installs the
asyncpg driver used by every postgresql+asyncpg:// DSN in this guide:
pip install "alchemiq[postgres]"
Extra |
What it adds |
|---|---|
|
|
|
|
|
Argon2 password hashing ( |
|
bcrypt password hashing ( |
|
|
|
Outbox/Relay worker via TaskIQ + aio-pika ( |
|
FastAPI CRUD router + dependency injection ( |
|
FastStream publisher + consumer DI ( |
|
Repository-level Redis caching ( |
|
Async PostgreSQL driver ( |
|
ClickHouse models + repository ( |
|
Alembic-based migration CLI ( |
Minimal end-to-end example¶
The steps below get a working database-backed service running from scratch.
Define a model. Subclass
Modeland declare fields using plain Python type annotations:import alchemiq from alchemiq import Model from alchemiq.types import PK, Email class User(Model): id: PK[int] name: str email: Email
Configure the engine. Call
configure()once at startup with an async-compatible DSN:alchemiq.configure("postgresql+asyncpg://user:password@localhost/mydb")
Create tables. Call
create_all()to emitCREATE TABLE IF NOT EXISTSfor every mapped model:await alchemiq.create_all()
Use a Repository. Instantiate
Repositorywith your model class to get a full CRUD surface:from alchemiq import Repository users = Repository(User) # create a row user = await users.create(name="Ada Lovelace", email="ada@example.com") # fetch by primary key found = await users.get(id=user.id) print(found.name) # Ada Lovelace
That is the complete setup. All queries are async/await; no synchronous mode is provided.