Skip to main content

The Precision ODM for Asynchronous MongoDB & Pydantic.

Project description

Vellum

The Precision ODM for Asynchronous MongoDB & Pydantic.

Vellum is a type-safe, async Python ODM for MongoDB built on Pydantic v2 and Motor. It provides a clean repository pattern, fluent aggregation builder, lifecycle hooks, optimistic concurrency, soft deletes, and transactions — all with full type hints.

Installation

pip install vellum-odm

Quick Start

from motor.motor_asyncio import AsyncIOMotorClient
from vellum import VellumBaseModel, VellumRepository, AggregationPipeline

# 1. Define a model
class User(VellumBaseModel):
    name: str
    email: str

    class Settings:
        collection_name = "users"
        indexes = [{"key": [("email", 1)], "unique": True}]

# 2. Connect and create a repository
client = AsyncIOMotorClient("mongodb://localhost:27017")
db = client["myapp"]
repo = VellumRepository(User, db)

# 3. CRUD
user = await repo.create(User(name="Alice", email="alice@example.com"))
fetched = await repo.get(user.id)
user.name = "Bob"
await repo.update(user.id, user)
await repo.delete(user.id)

# 4. Query
users = await repo.find({"name": "Alice"})
count = await repo.count({"name": "Alice"})

# 5. Aggregation
results = await (
    AggregationPipeline(repo.collection)
    .match({"status": "active"})
    .group("$department", total={"$sum": 1})
    .sort([("total", -1)])
    .execute()
)

Features

Feature Description
Type-safe queries Expression classes for all MongoDB operators (Eq, Gt, In, Regex, ElemMatch, ...)
Fluent aggregation AggregationPipeline with match, group, project, sort, unwind, lookup, etc.
Lifecycle hooks before_insert, after_insert, before_update, ... on your model
OCC OptimisticConcurrencyMixin — automatic version-based conflict detection
Soft delete SoftDeleteMixin — automatic filtering, soft_delete() / restore()
Transactions async with repo.transaction() as session:
FastAPI integration repository_factory for Depends injection
Aggregation output models Pass a Pydantic model to project() / group() for validated results

Documentation

  • Learning Guide — explains bugs found and concepts introduced
  • Roadmap — planned features and improvements

Requirements

  • Python >= 3.12
  • MongoDB >= 4.0 (transactions require a replica set)

License

MIT

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

vellum_odm-0.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

vellum_odm-0.1.0-py3-none-any.whl (24.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vellum_odm-0.1.0.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vellum_odm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9a09c0a4ba8a2ebd31c3f27a1beed8e331473fe887e879e3460eb5dfa2b4544a
MD5 e5e66279784da301f2aa09f718565ab8
BLAKE2b-256 55d958560c48fe39729dde79a67763d8c0ba9a72511968afc8d494bdda3b23bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for vellum_odm-0.1.0.tar.gz:

Publisher: ci.yml on wailbentafat/Vellum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: vellum_odm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vellum_odm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e2a8c778fe18eb42e2e859bd6bb8083fbf8370510996ca8f5776cb7c3c33f2d
MD5 6f755dad4d1743adc4462b5d4c29e581
BLAKE2b-256 a2010f4d14f32360f2648a73d80e99bb79fcf1c0480d4f8beddb08ac70323764

See more details on using hashes here.

Provenance

The following attestation bundles were made for vellum_odm-0.1.0-py3-none-any.whl:

Publisher: ci.yml on wailbentafat/Vellum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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