A syncrounous and asyncrounous Python ODM for MongoDB based on Pydantic
Project description
Documentation (Under construction): https://pyodmongo.dev
Source Code: https://github.com/mauro-andre/pyodmongo
pyodmongo
is a Python library that serves as an Object-Document Mapper (ODM) for MongoDB. It is built on top of the popular pydantic V2
library, making it easy to work with MongoDB documents in a Pythonic and efficient way.
With pyodmongo
, you can seamlessly map your Python classes to MongoDB documents, allowing you to work with data in a more intuitive and Pythonic manner. It simplifies the process of defining and interacting with MongoDB collections, documents, and queries.
Key Features
-
Integration with pydantic: Leverage the power of pydantic's data validation and modeling capabilities while working with MongoDB data.
-
Automatic Schema Generation: Define your MongoDB schema using pydantic models, and
pyodmongo
will automatically create the necessary MongoDB collections and ensure data consistency. -
Query Builder: Easily construct complex MongoDB queries using Python code, reducing the need for writing raw query strings.
-
Document Serialization: Serialize and deserialize Python objects to and from MongoDB documents effortlessly.
-
Async Support: Take advantage of asynchronous programming with
pyodmongo
to enhance the performance of your MongoDB operations. -
Active Development:
pyodmongo
is actively developed and maintained, with new features and improvements being regularly added.
Installation
You can install pyodmongo
using pip:
pip install pyodmongo
Contributing
Contributions to pyodmongo
are welcome! If you find any issues or have ideas for improvements, please open an issue or submit a pull request on the GitHub repository.
License
pyodmongo
is licensed under the MIT License. See the LICENSE file for more information.
Async exemple
from pyodmongo import AsyncDbEngine, DbModel
from typing import ClassVar
import asyncio
engine = AsyncDbEngine(mongo_uri='mongodb://localhost:27017', db_name='my_db')
class Product(DbModel):
name: str
price: float
is_available: bool
_collection: ClassVar = 'products'
box = Product(name='Box', price='5.99', is_available=True)
async def main():
result = await engine.save(box)
asyncio.run(main())
Sync exemple
from pyodmongo import DbEngine, DbModel
from typing import ClassVar
engine = DbEngine(mongo_uri='mongodb://localhost:27017', db_name='my_db')
class Product(DbModel):
name: str
price: float
is_available: bool
_collection: ClassVar = 'products'
box = Product(name='Box', price='5.99', is_available=True)
result = engine.save(box)
Project details
Release history Release notifications | RSS feed
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 pyodmongo-0.0.13-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be8eb3bd18aaaa1ea4be8dcaf691648c03e09637615f4741e94cb078c142899c |
|
MD5 | 4ccca3510c226dcc05b31c1453cd8c97 |
|
BLAKE2b-256 | fcc427c6758c1466b630f5b974610854ed1fad946fa5a09ca169d7496b241f64 |