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
andmotor
- ๐ง 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.