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
  • 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 mongospecs for msgspec only
  • pip install mongospecs[pydantic] for msgspec and pydantic only
  • pip install mongospecs[attrs] for msgspec and attrs only
  • pip 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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongospecs-0.1.1-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

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

Hashes for mongospecs-0.1.1.tar.gz
Algorithm Hash digest
SHA256 05737392693030da1b32e55c8ce02a0558aea9a8fa00446148c4797f52155393
MD5 f180ae41e3150a588caa9b7a42791ba8
BLAKE2b-256 5b5f6ac0f5f31efc31e02ae9aa0a0ffc0dcb470428d698cb53972d2eae09fd3a

See more details on using hashes here.

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

Hashes for mongospecs-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 649bc9640c7af04dcd1c52405e48b3dc6a23563bd189ef7afb73bec039ac2e64
MD5 c5867ec7676f7a7c49c4c7b0d28b05f0
BLAKE2b-256 008ca7c96ef145b4f51388cdc7858cd9d56047b74c7ce2fadf1c868575380921

See more details on using hashes here.

Supported by

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