Skip to main content

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

pyodmongo-1.6.4.tar.gz (758.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyodmongo-1.6.4-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file pyodmongo-1.6.4.tar.gz.

File metadata

  • Download URL: pyodmongo-1.6.4.tar.gz
  • Upload date:
  • Size: 758.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for pyodmongo-1.6.4.tar.gz
Algorithm Hash digest
SHA256 ba1b1a55bf8879c0c60ba95c97cff5da998ad3c1e0f887978c8ca36119c608b2
MD5 47ac19ee77244e7f89e921398a8a7c42
BLAKE2b-256 2e3e67c6cf1f4b66b33c4568c9a58821b8f0b5c8eb6ab20b09395d8865aed524

See more details on using hashes here.

File details

Details for the file pyodmongo-1.6.4-py3-none-any.whl.

File metadata

  • Download URL: pyodmongo-1.6.4-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for pyodmongo-1.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 bc2c0b699a1940323d1692413bcbcbc852e399e8a924edc7924ba8f00ffc6be2
MD5 235e98da6870f52f41cdb9f127c4e75a
BLAKE2b-256 141d6900dade23555150673571796dcbfb4c6127325bb822b0b27e3298feadcc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page