A MongoDB Python ORM, built on Pydantic and PyMongo.
Project description
Mongomantic = Pymongo + Pydantic
Mongomantic is an easy-to-use, easy-to-learn wrapper around PyMongo, built around Pydantic models.
Usage
pip install mongomantic
API
from mongomantic import BaseRepository, MongoDBModel
class User(MongoDBModel):
first_name: str
last_name: str
class UserRepository(BaseRepository):
@property
def _model(self): # Define model type
return User
@property
def _collection(self): # Define collection name
return "user"
user = User(first_name="John", last_name="Smith")
user_repo = UserRepository()
user = user_repo.save(user)
user.id # ObjectId that was saved
Your Opinion is Needed
Mongomantic can be kept as a simple wrapper around PyMongo, or developed into a miniature version of Mongoengine that's built on Pydantic. The first direction would result in the following API:
# Direct pymongo wrapper
users = user_repo.find({"$and": [{"age": {"$gt": 12}}, {"name": "John"}]})
# But matches can be done as keyword arguments
john = user_repo.find(name="John")
On the other hand, a more complex version of Mongomantic could lead to:
# More Pythonic way of writing queries
users = user_repo.find(User.age > 12, name="John")
# Matches still compact
john = user_repo.find(name="John")
Please submit your vote below.
Simple PyMongo Wrapper - Prefer speed and native mongodb filters More Complex Wrapper - Pythonic Filters
🚀 TODO
- Documentation
- Basic API similar to mongoengine, without any queryset logic
- Built on Pydantic models, no other schema required
- BaseRepository responsible for all operations (instead of the model itself)
- ProductionRepository derived from BaseRepository with all errors handled
- Repository/model plugin framework (ex. SyncablePlugin, TimestampedPlugin, etc.)
- Wrapper for aggregation pipelines
- Mongomock tests
- Flexible connect() function wrapper around PyMongo client (aliases, replica sets, retry writes, etc.)
- Clean up imports and expose essentials in main file
🛡 License
This project is licensed under the terms of the MIT
license. See LICENSE for more details.
📃 Citation
@misc{mongomantic,
author = {mongomantic},
title = {A MongoDB Python ORM, built on Pydantic and PyMongo.},
year = {2021},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/RamiAwar/mongomantic}}
}
Credits
This project was generated with python-package-template
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mongomantic-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f48ba1c504cd9bec5dc91c3250e192d295c23fc07ef058536d01caf5df31f2cf |
|
MD5 | ab10970e33b5d030837d9f3987df273b |
|
BLAKE2b-256 | 98badc09c75c63fdac7c591f0dc5fb883cc245985744eda0d6d69fae7430b756 |