Skip to content

Pydongo

Pydongo is a lightweight and expressive ORM for MongoDB powered by Pydantic.

It brings structure and type safety to your unstructured NoSQL world โ€” giving you clean, Pythonic control over your MongoDB documents.


๐Ÿš€ Why Use Pydongo?

  • โœ… Pydantic-first: Write your models as BaseModel classes โ€” just like you're used to
  • ๐Ÿ”„ Sync + Async support via pymongo and motor
  • ๐Ÿง  Elegant Query DSL: Express Mongo filters using ==, >, &, | and more
  • ๐Ÿงช Built for Testing: In-memory mock driver makes unit testing easy
  • ๐Ÿงฐ No boilerplate: Automatically connects models to collections
  • ๐Ÿ“ฆ Tiny but powerful: Focused API, zero clutter

๐Ÿงฑ Example

from pydantic import BaseModel
from pydongo import as_document, as_collection
from pydongo.drivers.sync_mongo import DefaultMongoDBDriver

class User(BaseModel):
    name: str
    age: int

driver = DefaultMongoDBDriver("mongodb://localhost:27017", "mydb")
driver.connect()

# Insert a document
doc = as_document(User(name="Alice", age=30), driver)
doc.save()

# Query with expressive DSL
collection = as_collection(User, driver)
results = collection.find(collection.age > 25).all()

for user in results:
    print(user.name, user.age)

driver.close()

๐Ÿ“š Learn More


๐Ÿ’ฌ Get Involved

Contributions welcome!
Check out the contributing guide or open an issue on GitHub.


๐Ÿงพ License

Pydongo is open source under the MIT License.