A syncrounous and asyncrounous Python ODM for MongoDB based on Pydantic
Project description
Documentation: https://pyodmongo.dev
Source Code: https://github.com/mauro-andre/pyodmongo
PyODMongo is a modern Python library that functions as a robust Object-Document Mapper (ODM) for MongoDB. Leveraging the power of Pydantic V2, it seamlessly bridges the gap between Python and MongoDB, offering an intuitive and efficient way to interact with MongoDB documents.
By using PyODMongo, you can effortlessly map your Python classes to MongoDB documents, allowing for a more Pythonic approach to handling data. This library simplifies the entire process of defining and working with MongoDB collections, documents, and queries.
PyODMongo is built on top of Pydantic V2, making the DbModel
class an extension of Pydantic's BaseModel
. This means that all the rich functionality of Pydantic's BaseModel
, including Validators, Fields and Model Config, is readily available in DbModel
.
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
File details
Details for the file pyodmongo-1.4.2.tar.gz
.
File metadata
- Download URL: pyodmongo-1.4.2.tar.gz
- Upload date:
- Size: 756.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 40ffff91c2e6645cf9e84fa8d43b3ff9c5c250476c8b4470d613e62d098c0676 |
|
MD5 | 067111d253ba699880b9e8d89a93f19a |
|
BLAKE2b-256 | ee8d445ed23bb1284a196d48f145b3cbadc24dae93f723dd17daa3d55bac5439 |
File details
Details for the file pyodmongo-1.4.2-py3-none-any.whl
.
File metadata
- Download URL: pyodmongo-1.4.2-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1515cba603d52315d7dddec84bfa958dce2976b6bac8ebd114e9f1f54542f84 |
|
MD5 | a4bdd502e726e4fdc07b7a01a93b79cf |
|
BLAKE2b-256 | ead9d09c84c840a45c18fa49513f4e55b9ef8aee129a9822c922a86b13f49ce6 |