Built with ❤️ for speed & developer ergonomics
翻译准备中
正在加载完整 README。
查看完整 README ↗Ferro is an async ORM for Python: you declare Pydantic models, and a Rust engine builds the SQL, runs it and turns rows into model instances. Its runtime dependencies are Pydantic and pydantic-settings.
Here is a model, a query and the result:
import asyncio
from ferro import Field, Model, connect, engines
class User(Model):
id: int | None = Field(default=None, primary_key=True)
username: str
is_active: bool = True
async def main():
await connect("sqlite::memory:", auto_migrate=True)
async with engines.session():
await User.create(username="alice")
await User.create(username="bob", is_active=False)
active_users = await User.where(lambda user: user.is_active == True).all()
print(f"Found {len(active_users)} active users.")
asyncio.run(main())
Running it prints:
Found 1 active users.
Every ORM call runs inside async with engines.session():, which routes it to the connection you opened. auto_migrate=True creates the table on connect; it suits development and tests.
__init__.pyo3-async-runtimes and SQLx.Ferro ships pre-compiled wheels for macOS, Linux and Windows:
pip install ferro-orm
# With the migrations CLI (ferro migrate)
pip install "ferro-orm[cli]"
# With the Alembic bridge
pip install "ferro-orm[alembic]"
Auto-migrate keeps a development database current. For production, ferro migrate new writes reviewed migration files and ferro migrate up applies them; see Schema management. To use more than one database, register named connections with connect(..., name="..."); see Connections.