Skip to content

⚡ Blazing-fast async MongoDB ODM with msgspec serialization and automatic collection binding

License

Notifications You must be signed in to change notification settings

TAlyssa931993/mongospec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐾 MongoSpec: A High-Performance Async MongoDB ODM

MongoSpec Logo

Welcome to the MongoSpec repository! This project offers a blazing-fast asynchronous Object Document Mapper (ODM) for MongoDB. It utilizes msgspec serialization and provides automatic collection binding, making database interactions seamless and efficient.

Table of Contents

Features

  • Asynchronous Operations: MongoSpec leverages async programming to handle multiple database requests without blocking.
  • High Performance: Optimized for speed, MongoSpec minimizes latency and maximizes throughput.
  • Automatic Collection Binding: Automatically binds your Python classes to MongoDB collections, simplifying data handling.
  • Msgspec Serialization: Utilizes msgspec for efficient serialization and deserialization of data.
  • Compatibility: Works seamlessly with popular libraries like Motor and PyMongo.

Installation

To get started with MongoSpec, you need to install it using pip. Run the following command in your terminal:

pip install mongospec

Usage

Here's a quick example of how to use MongoSpec in your Python application.

Basic Example

import asyncio
from mongospec import MongoSpec

async def main():
    # Create a MongoSpec instance
    db = MongoSpec('mongodb://localhost:27017/mydatabase')

    # Define a model
    class User:
        def __init__(self, name, age):
            self.name = name
            self.age = age

    # Insert a new user
    await db.users.insert_one(User("Alice", 30))

    # Fetch users
    users = await db.users.find()
    for user in users:
        print(user)

# Run the async main function
asyncio.run(main())

Configuration

You can customize MongoSpec by passing configuration options during initialization. Here’s how:

db = MongoSpec('mongodb://localhost:27017/mydatabase', options={"maxPoolSize": 50})

Error Handling

MongoSpec provides built-in error handling for database operations. You can catch exceptions as follows:

try:
    await db.users.insert_one(User("Bob", 25))
except Exception as e:
    print(f"An error occurred: {e}")

Contributing

We welcome contributions to MongoSpec! If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and commit them.
  4. Push your branch to your fork.
  5. Open a pull request with a clear description of your changes.

Please ensure your code adheres to the project's coding standards and includes tests where applicable.

License

MongoSpec is licensed under the MIT License. See the LICENSE file for details.

Releases

To view the latest releases, please visit our Releases section. Here you can find the latest versions and download the necessary files for installation.

Contact

For any inquiries or feedback, please reach out via GitHub issues or contact me directly at your_email@example.com.


Thank you for checking out MongoSpec! We hope it helps you in your MongoDB projects. For the latest updates and releases, don't forget to visit our Releases page.

About

⚡ Blazing-fast async MongoDB ODM with msgspec serialization and automatic collection binding

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages