mongotic
MongoDB + SQLAlchemy v2 + Pydantic — use familiar SA v2 query syntax with MongoDB, define models with Pydantic.
from mongotic import create_engine, select
from mongotic.orm import sessionmaker
engine = create_engine("mongodb://localhost:27017")
Session = sessionmaker(bind=engine)
with Session() as session:
users = session.scalars(select(User).where(User.age > 18)).all()
Why mongotic?
- Familiar API —
select(),session.scalars(),ScalarResultmirror SQLAlchemy v2. - Pydantic models — schema validation and IDE autocomplete out of the box.
- No replica set required — works on standalone MongoDB instances.
- Bulk operations —
insert(),update(), anddelete()viasession.execute(), returning aResultwith.rowcountand.inserted_ids. - Column projection —
select(User.name, User.email)returns lightweightRowresults; single-columnselect(User.name)unwraps to plain values viasession.scalars(). - Full async API —
mongotic.asynciomirrors the sync session on top ofpymongo.AsyncMongoClient.
Installation
Navigation
| Page | What it covers |
|---|---|
| Quickstart | End-to-end example in under 5 minutes |
| Querying | select(), filters, logical combinators, string/range/null operators, distinct, projection, ScalarResult |
| Session | Session lifecycle, writes, refresh, merge, expunge/expire, state properties |
| Indexes | __indexes__ declaration and create_indexes() |
| Async | Full async API via mongotic.asyncio |
| Migration Guide (v0.4 → v0.5) | Breaking changes and new features in v0.5.0 |
| Migration Guide (v0.2 → v0.3) | Breaking changes from v0.2.0 |
| Design | Architecture rationale |