Skip to main content

Async ODM for MongoDB

Project description

Mongotoy Logo

Async ODM for MongoDB.

Version Supported Python Versions


Mongotoy is a comprehensive asynchronous Object-Document Mapper (ODM) designed to simplify interactions with MongoDB databases in Python applications. Leveraging the Motor asynchronous MongoDB driver, Mongotoy seamlessly integrates asynchronous programming with MongoDB, providing developers with a powerful toolset for building high-performance applications. This integration allows for efficient communication with MongoDB databases, ensuring optimal scalability and responsiveness. With Mongotoy, developers can harness the full potential of MongoDB's features while enjoying the benefits of asynchronous programming, making it an ideal choice for modern, data-driven applications


Features

  • Asynchronous Power: Mongotoy leverages the asynchronous paradigm of Python, enabling efficient management of I/O operations for optimal performance and responsiveness in applications.

  • Based on Motor Driver: Mongotoy is built on top of the asynchronous Motor MongoDB driver, ensuring seamless integration with asynchronous Python applications.

  • Schemaless Flexibility: With a schemaless design, Mongotoy empowers developers to work with MongoDB databases without rigid schemas, adapting to evolving data models effortlessly.

  • Intuitive API: Mongotoy features an elegant and straightforward API facilitating common database operations.

  • Flexible Configuration Options: Mongotoy offers extensive configuration options at both the database and document levels, enabling fine-tuning of MongoDB interactions for optimal performance and reliability.

  • Custom Data Types Support: Mongotoy simplifies handling of custom data types and allows defining new types through Data Mapper classes, enhancing data integrity and consistency.

  • Object-Document Mapping: Simplifying MongoDB document manipulation, Mongotoy maps Python objects to MongoDB documents seamlessly, enabling intuitive and object-oriented interactions.

  • Document Serialization: Mongotoy supports serialization of documents into JSON, BSON, or Python dictionaries, enabling seamless integration with different parts of an application stack.

  • Document Inheritance Support: Mongotoy provides robust support for document inheritance, enabling the creation of hierarchical data models and promoting code reuse and maintainability.

  • Python Type Hint Support: Mongotoy allows developers to define document fields using Python type hints, enhancing code readability and enabling type checking.

  • Relationship Management: Simplifying relationship management between documents, Mongotoy offers robust support for references and embedded documents, automating insertions, deletions, and updates.

  • Automatic Operation Handling: Mongotoy automates insertion and deletion management, ensuring data integrity and consistency across related documents.

  • Query Building: Mongotoy provides a powerful query building interface for constructing complex queries using Pythonic syntax.

  • Index Management: Mongotoy simplifies the management of database indexes, optimizing query performance for efficient data retrieval.

  • Transactions: Supporting MongoDB transactions, Mongotoy ensures data consistency and atomicity across multiple operations within a single transactional context.

  • Geospatial Data Support: Mongotoy offers robust support for geospatial data types, facilitating storage, querying, and spatial analysis.

  • Database Seeding Management: With built-in support for database seeding, Mongotoy streamlines the initialization of databases with predefined data sets, enhancing developer productivity.

  • Support for Capped Collections: Mongotoy natively supports capped collections in MongoDB, ideal for scenarios requiring fixed-size, ordered datasets.

  • Time Series Collections Management: Mongotoy provides robust support for managing time series data in MongoDB, optimized for storing and querying time-stamped data points.

  • GridFS File Handling: Mongotoy seamlessly integrates with MongoDB's GridFS storage system for efficient handling of large files, offering a high-level interface for file management within MongoDB.

Minimal Example

Let's begin with a minimal example by defining a document and performing CRUD operations on the database.

import asyncio
from mongotoy import Document, Engine
import datetime


class Person(Document):
    name: str
    last_name: str
    dob: datetime.date

    
# Create database engine
db = Engine('test-db')


async def main():
    # Create a new Person instance
    person = Person(
        name='John',
        last_name='Doe',
        dob=datetime.date(1990, 12, 25)
    )    
    
    # Connect to the MongoDB database
    await db.connect('mongodb://localhost:27017')
    
    # Open a database session
    async with db.session() as session:
        
        # Save the person to the database
        await session.save(person)
        
        # Fetch all persons from database
        async for c in session.objects(Person):
            print(c.dump_dict())
            
        # Update person dob
        person.dob=datetime.date(1995, 10, 25)
        await session.save(person)
        
        # Delete person from database
        await session.delete(person)


if __name__ == '__main__':
    asyncio.run(main())

Installing

To install, just run:

pip install mongotoy

Or, if using poetry:

poetry add mongotoy

Extras

See full documentation at: https://gurcuff91.github.io/mongotoy

If you like this project !!

Buy Me A Coffee

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

mongotoy-0.1.2.tar.gz (32.8 kB view details)

Uploaded Source

Built Distribution

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

mongotoy-0.1.2-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file mongotoy-0.1.2.tar.gz.

File metadata

  • Download URL: mongotoy-0.1.2.tar.gz
  • Upload date:
  • Size: 32.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.8 Windows/10

File hashes

Hashes for mongotoy-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c52c04dda6948b1d070b7304447ba44c052a9274db8e9e809eaefed35739cbf3
MD5 3504c3137fe2fbd4be890a6bb0b0889f
BLAKE2b-256 92bcdff72bffa6becbc3d71c1f2f779c0d092deeb95a603d5a4a8ae028cc521e

See more details on using hashes here.

File details

Details for the file mongotoy-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: mongotoy-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 36.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.11.8 Windows/10

File hashes

Hashes for mongotoy-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4d510085b81ec600f1b26fe23f065fbe983ebe9df311578e93e3fe2b052bbb2
MD5 004f7a8f9d5017733abef0de8a43c6d6
BLAKE2b-256 c973848b5c35015b85f382c56de63d7fdd97531244f932cd92db30687238bbb1

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