Document object mapper for pydantic and pymongo
Project description
Document object mapper for pydantic and pymongo
Documentation
Usage
Install:
$ pip install pydantic-mongo
from pydantic import BaseModel
from pydantic_mongo import AbstractRepository, ObjectIdField
from pymongo import MongoClient
class Foo(BaseModel):
count: int
size: float = None
class Bar(BaseModel):
apple = 'x'
banana = 'y'
class Spam(BaseModel):
id: ObjectIdField = None
foo: Foo
bars: List[Bar]
class SpamRepository(AbstractRepository[Spam]):
class Meta:
collection_name = 'spams'
client = MongoClient(os.environ["MONGODB_URL"])
database = client[os.environ["MONGODB_DATABASE"]]
spam_repository = SpamRepository(database=database)
foo = Foo(count=1,size=1.0)
bar = Bar()
spam = Spam(foo=foo,bars=[bar])
spam_repository.save(spam)
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
pydantic-mongo-0.0.1.tar.gz
(4.9 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_mongo-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9656c319193a6851026d63c189a3cb5eafccb5a6f7d4d17d30bcd458e8d2b923 |
|
MD5 | 10f8f655197561966ebc45c9abfc0a48 |
|
BLAKE2b-256 | 66717bd54778ed19397ae7768f7124e4398db0fd351aa4bda3315d5d10b3e2f8 |