Skip to content

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 APIselect(), session.scalars(), ScalarResult mirror SQLAlchemy v2.
  • Pydantic models — schema validation and IDE autocomplete out of the box.
  • No replica set required — works on standalone MongoDB instances.
  • Bulk operationsinsert(), update(), and delete() via session.execute(), returning a Result with .rowcount and .inserted_ids.
  • Column projectionselect(User.name, User.email) returns lightweight Row results; single-column select(User.name) unwraps to plain values via session.scalars().
  • Full async APImongotic.asyncio mirrors the sync session on top of pymongo.AsyncMongoClient.

Installation

pip install mongotic
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