Async ODM for MongoDB based on Motor & Pydantic
Project description
MangoODM
MangoODM — lightweight and easy-to-use ODM (Object Document Mapper) library for Python, designed to work asynchronously with MongoDB using the motor driver.
Supports Pydantic models and MongoDB sessions.
Features
- Simple model definition using Pydantic
- Model registration and automatic collection handling
- Asynchronous CRUD operations: insert, find, update, delete
- Support for MongoDB sessions for transaction safety
- Logging for important events and errors
Installation
pip install mangodb.py
Usage
Define your model
from mango impot MangoModel
class GDBeach(MangoModel):
name: str
role: str
Initialize ODM and register model
import asyncio
from motor.motor_asyncio import AsyncIOMotorClient
from mango import MangoODM, MangoModel
class GDBeach(MangoModel):
name: str
role: str
async def main():
client = AsyncIOMotorClient("mongodb://localhost:27017") # you also can use srv
db = client["MangoDB"]
odm = MangoODM(db)
odm.register_model(GDBeach)
async with await client.start_session() as session:
insert_result = await odm.insert_one("GDBeach", session=session, name="xSodium", role="soda")
print(f"Inserted document ID: {insert_result.inserted_id}")
found_doc = await odm.find_one("GDBeach", session=session, name="xSodium")
print(f"Found document: {found_doc}")
asyncio.run(main())
that's all!
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mangodb_py-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mangodb_py-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fd3eaa3cccd523c38e95a62f2c9c2b317baea9ba76346e2bbe13e7e861a60e8
|
|
| MD5 |
05ae3e5e047d585e06cb3a8fd91840b2
|
|
| BLAKE2b-256 |
79817c228a88d598dfad2a755ab8c619077534045dc777930c071af7aed1751b
|