Skip to main content

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


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 details)

Uploaded Source

Built Distribution

mongospecs-0.1.0-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file mongospecs-0.1.0.tar.gz.

File metadata

  • Download URL: mongospecs-0.1.0.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for mongospecs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 061762bde99c40e460384c54f62a1995e921ad25749f14d204828bc280e3cafa
MD5 4d22fa5304ccd8c4330a77b2a28113ce
BLAKE2b-256 8978ba40db8894352b5a1427d4bc5190e14c6618e06b5ba210f74003914e9c1c

See more details on using hashes here.

File details

Details for the file mongospecs-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mongospecs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for mongospecs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa8e29d7bbcfe5f5501694654ce3e1e3b383e33b989c6d00735e7d9e66939342
MD5 c5f414600aaeae1ced92b20914670eba
BLAKE2b-256 afb4ae9e350182c23da13d63c06d26f6e06b14ed929210894afd59950d736426

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page