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.4.tar.gz (17.0 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.4-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

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

Hashes for mongospecs-0.1.4.tar.gz
Algorithm Hash digest
SHA256 2ed569b1bec03e265d56f206e9f674b603e3eeef83708647d1e03539db41265c
MD5 b44180c8c9855d20f89be050a0316b45
BLAKE2b-256 7924749cece3fcfd345b03e16995e2e0855d6b73c3269cdd9707ed9d8923e162

See more details on using hashes here.

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

Hashes for mongospecs-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 23f2b0eb185d77b0d2f78a3d32cbda2163cef3cc9f8e8f3e391d04c0180fccee
MD5 b37b336084f82919912366ee292e9ab1
BLAKE2b-256 10c71eb8f57e4a8fd8e0013d94b601fd0642b9a59f2e44b4f63219bf2525ad2f

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