https://github.com/codello/Motor-ODM
A MongoDB ODM based on Motor and Pydantic.
https://github.com/codello/Motor-ODM
asyncio mongodb motor odm pydantic pymongo python3
Last synced: 4 months ago
JSON representation
A MongoDB ODM based on Motor and Pydantic.
- Host: GitHub
- URL: https://github.com/codello/Motor-ODM
- Owner: codello
- License: mit
- Created: 2020-04-06T10:18:51.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-09-03T20:56:58.000Z (10 months ago)
- Last Synced: 2024-10-02T06:54:59.742Z (9 months ago)
- Topics: asyncio, mongodb, motor, odm, pydantic, pymongo, python3
- Language: Python
- Size: 95.7 KB
- Stars: 17
- Watchers: 4
- Forks: 5
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Motor-ODM
[](https://github.com/Codello/Motor-ODM/actions?query=workflow%3ABuild)
[](https://motor-odm.readthedocs.io/en/latest/?badge=latest)
[](https://codecov.io/gh/Codello/Motor-ODM)
[](https://requires.io/github/Codello/Motor-ODM/requirements/?branch=master)
[](https://pypi.org/project/Motor-ODM/)
[](https://pypi.org/project/Motor-ODM/)
[](https://github.com/psf/black)A MongoDB ODM based on Motor and Pydantic.
The project code is hosted on [GitHub](https://github.com/Codello/Motor-ODM), documentation on [ReadTheDocs](https://motor-odm.readthedocs.io/).
## Installation
```shell script
pip install Motor-ODM
```## Quick Start
```python
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](https://motor-odm.readthedocs.io/).