simple mongo ODM with support for msgspec, pydantic, and attrs
Project description
mongospecs
Built on top of the https://github.com/GetmeUK/MongoFrames ODM, with:
- Pydantic (
BaseModel
), attrs (@define
), and msgspec (Struct
) support for defining schema models (specs) - Type-hints
Example
# Import Spec, either...
## 1. with pydantic:
from mongospecs.pydantic import Spec
## 2. with msgspec:
from mongospecs.msgspec import Spec
## 3. with attrs:
from mongospecs.attrs import Spec
# Define schema model
class Dragon(Spec):
_collection = "dragons" # Optional. If not defined, uses the class name by default.
name: str
breed: Optional[str] = None
# create
burt = Dragon(name="Burt", breed="Cold-drake")
print(burt.name) # Burt
print(burt.breed) # Cold-drake
# insert
burt.insert()
print(burt.id) # inserted document ObjectId
# fetch
doc = Dragon.find_one({"name": "Burt"}) # returns raw mongo document
# delete
burt.delete()
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
mongospecs-0.1.0.tar.gz
(14.4 kB
view hashes)
Built Distribution
mongospecs-0.1.0-py3-none-any.whl
(17.7 kB
view hashes)
Close
Hashes for mongospecs-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa8e29d7bbcfe5f5501694654ce3e1e3b383e33b989c6d00735e7d9e66939342 |
|
MD5 | c5f414600aaeae1ced92b20914670eba |
|
BLAKE2b-256 | afb4ae9e350182c23da13d63c06d26f6e06b14ed929210894afd59950d736426 |