This guide takes you from pip install to a working query in under 5 minutes.
pip install bridgeBuild from source (requires Rust toolchain):
pip install maturin && maturin developCreate a file called models.py:
from bridge import BaseModel
class User(BaseModel):
table = "users"
_fields = ["id", "username", "email"]
id: str
username: str
email: strEvery model needs:
table— the SQL table name_fields— the list of column names- Type annotations for each field
import asyncio
from bridge import connect, transaction
from models import User
async def main():
await connect("sqlite::memory:")
async with transaction() as tx:
user = await User.create(tx, username="alice", email="alice@example.com")
print(f"Created user {user.id}")
found = await User.find_one(tx, id=user.id)
print(found.to_dict())
asyncio.run(main())Output:
Created user 550e8400-e29b-41d4-a716-446655440000
{'id': '550e8400-e29b-41d4-a716-446655440000', 'username': 'alice', 'email': 'alice@example.com'}
connect()initializes a connection pool to the database (SQLite in-memory here).transaction()opens a session with an active transaction.User.create()inserts a row and auto-generates a UUID primary key.User.find_one()looks up by primary key (checks the identity map first).- The
async withblock commits on success, rolls back on exception.
- Defining models — fields, types, composite keys
- Basic queries — filter, limit, select, delete
- Relationships — one-to-many, many-to-many