A MongoDB ODM based on Motor and Pydantic.
Project description
Motor-ODM
A MongoDB ODM based on Motor and Pydantic.
The project code is hosted on GitHub, documentation on ReadTheDocs.
Installation
pip install Motor-ODM
Quick Start
from motor.motor_asyncio import AsyncIOMotorClient
from motor_odm import Document
# Create a custom model by subclassing Document
class User(Document):
class Mongo:
# Set the collection name
collection = "users"
# Add attributes to your model
username: str
age: int
# Connect your model to a database
client = AsyncIOMotorClient(...)
Document.use(client.get_default_database())
# Create documents and save them to the database
u = User(username="John", age=20)
await u.insert()
# Query the database
async for user in User.all():
print(user.username)
For a more complete overview have a look at the docs.
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
Motor-ODM-0.1.dev0.tar.gz
(17.1 kB
view hashes)
Built Distribution
Close
Hashes for Motor_ODM-0.1.dev0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86bc245ed8c54f72e833f71985785b0132f6f181527bc5de6a4f3a67301d5022 |
|
MD5 | 19cf2c22f815c4b6273791e3be95a326 |
|
BLAKE2b-256 | 8d3e2e6dc5e6cddcfce5b3ccee768206285af6123eb6bc1dd2992fbf812c024c |