NextORM is a modern, async-capable Python ORM — a fully-typed successor to PonyORM.
It brings the expressive PonyORM query style into the era of Python 3.12+ type annotations,
asyncio, and first-class migration tooling.
Async-ready
Every operation has both a sync and async counterpart. NextORM auto-detects
the event loop — no configuration required.
Fully typed
Field types are real Python generics (Req[str], PK[int]).
Pyright and mypy understand them without plugins.
Migrations built-in
Schema diffing, file-based migrations, and a CLI — no third-party migration framework needed.
from nextorm import Database, Entity, PK, Req, Opt, Set, db_session
class Tag(Entity):
name: Req[str]
products: Set["Product"]
class Product(Entity):
name: Req[str]
price: Req[float]
desc: Opt[str]
tags: Set[Tag]
db = Database(entities=[Tag, Product])
db.bind("sqlite", ":memory:")
db.generate_mapping(create_tables=True)
with db_session:
p = Product(name="Widget", price=9.99)
p.tags.add(Tag(name="new"))
products = db.select(Product).filter(Product.price < 20).fetch_all()
User guide
- Getting Started
- Defining Entities
- Entity registration
- Field types
- Primary keys
- Default values
- Custom column names
- Custom table names
- Unique constraints and indexes
- Special column types
- Local (transient) fields
- Lifetime hooks
- Single-table inheritance
- Enum fields
- Working with entity instances
- Positional argument shorthands
- Field and Relation Marker Options
- The Query API
- Sessions & Transactions
- Relations
- Async Usage
- Migrations
- Connection Pooling
- Debugging & Performance
Reference
Internals
Migration guide