Introducing mongospec — a blazing-fast async ODM, built on mongojet + msgspec (Python 3.13+)

PyPI
Python
License

Why another ODM?

I couldn’t find a truly minimal, async-first ODM that combines
the fastest driver I know (mongojet) with the fastest (de)serializer I know (msgspec).
So I wrote mongospec — a zero-boilerplate layer that does just enough:

  • Ultra-fastmongojet driver + msgspec dataclasses
  • Async everywhere ⇢ awaitable CRUD, bulk helpers, cursors
  • Automatic collection binding ⇢ no manual wiring
  • Declarative indexespymongo-style IndexModels right on the model
  • Python 3.13+ only ⇢ modern typing, no legacy fall-backs

:warning: Status: first public release, no test suite yet.
I’m looking for contributors to add coverage, benchmarks, docs & examples.


Quick start

pip install mongospec
import asyncio
from datetime import datetime
from typing import ClassVar, Sequence

import mongojet, msgspec, mongospec
from mongospec import MongoDocument
from mongojet import IndexModel


class User(MongoDocument):
    __collection_name__ = "users"
    __indexes__ = [IndexModel(keys=[("email", 1)], options={"unique": True})]

    name: str
    email: str
    created_at: datetime = msgspec.field(default_factory=datetime.now)


async def main():
    client = await mongojet.create_client("mongodb://localhost:27017")
    await mongospec.init(client.example_db, document_types=[User])

    user = User(name="Bob", email="bob@example.com")
    await user.insert()
    print("Inserted:", user)

    fetched = await User.find_one({"email": "bob@example.com"})
    print("Fetched :", fetched)

    await fetched.delete()
    await mongospec.close()

if __name__ == "__main__":
    asyncio.run(main())

Get involved

Open issues / PRs are welcome — especially tests.
Feedback on API design is also appreciated.