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
- Spec adapters
- Build a spec out of existing BaseModels, attrs classes, or Structs
- Raw BSON encode/decode for specs/mongo documents
Install
Choose from one of the following:
pip install mongospecsfor msgspec onlypip install mongospecs[pydantic]for msgspec and pydantic onlypip install mongospecs[attrs]for msgspec and attrs onlypip install mongospecs[pydantic,attrs]for msgspec, pydantic, and attrs
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
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.1.tar.gz
(15.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongospecs-0.1.1.tar.gz.
File metadata
- Download URL: mongospecs-0.1.1.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05737392693030da1b32e55c8ce02a0558aea9a8fa00446148c4797f52155393
|
|
| MD5 |
f180ae41e3150a588caa9b7a42791ba8
|
|
| BLAKE2b-256 |
5b5f6ac0f5f31efc31e02ae9aa0a0ffc0dcb470428d698cb53972d2eae09fd3a
|
File details
Details for the file mongospecs-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mongospecs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 18.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.20
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
649bc9640c7af04dcd1c52405e48b3dc6a23563bd189ef7afb73bec039ac2e64
|
|
| MD5 |
c5867ec7676f7a7c49c4c7b0d28b05f0
|
|
| BLAKE2b-256 |
008ca7c96ef145b4f51388cdc7858cd9d56047b74c7ce2fadf1c868575380921
|