Mongox is a an async MongoDB ODM (Object Document Mapper)built on top of Motor and Pydantic.
Mongox has a simple syntax, is easy to pick-up for people who have experience working with Python ORMs and is fully type-annotated.
You can install the python package:
pip install mongox
And you can define your models/collections using the Pydantic syntax:
import asyncio
import mongox
client = mongox.Client("mongodb://localhost:27017")
db = client.get_database("test_db")
class Movie(mongox.Model):
name: str
year: int
class Meta:
collection = db.get_collection("movies")
You can now insert and query some collections:
movie = await Movie(name="Forrest Gump", year=1994).insert()
Since Mongox is built on top of Pydantic, it plays well with Mypy and has auto-complete in IDE.
You can then query the document with:
movie = await Movie.query(Movie.name == "Forrest Gump").get()
Or to get all collections:
movies = await Movie.query().all()
Please visit the project page for documentation and full info here.
Top comments (0)