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.
- 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.
To get started with MongoSpec, you need to install it using pip. Run the following command in your terminal:
pip install mongospecHere's a quick example of how to use MongoSpec in your Python application.
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())You can customize MongoSpec by passing configuration options during initialization. Here’s how:
db = MongoSpec('mongodb://localhost:27017/mydatabase', options={"maxPoolSize": 50})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}")We welcome contributions to MongoSpec! If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your branch to your fork.
- 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.
MongoSpec is licensed under the MIT License. See the LICENSE file for details.
To view the latest releases, please visit our Releases section. Here you can find the latest versions and download the necessary files for installation.
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.