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.4.tar.gz
(17.0 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.4.tar.gz.
File metadata
- Download URL: mongospecs-0.1.4.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ed569b1bec03e265d56f206e9f674b603e3eeef83708647d1e03539db41265c
|
|
| MD5 |
b44180c8c9855d20f89be050a0316b45
|
|
| BLAKE2b-256 |
7924749cece3fcfd345b03e16995e2e0855d6b73c3269cdd9707ed9d8923e162
|
File details
Details for the file mongospecs-0.1.4-py3-none-any.whl.
File metadata
- Download URL: mongospecs-0.1.4-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.9.21
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23f2b0eb185d77b0d2f78a3d32cbda2163cef3cc9f8e8f3e391d04c0180fccee
|
|
| MD5 |
b37b336084f82919912366ee292e9ab1
|
|
| BLAKE2b-256 |
10c71eb8f57e4a8fd8e0013d94b601fd0642b9a59f2e44b4f63219bf2525ad2f
|