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

Uploaded Source

Built Distribution

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

Uploaded Python 3

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