Skip to main content

varco-beanie

PyPI version Python License: Apache 2.0 GitHub

Beanie (Motor / MongoDB) async backend for varco.

Generates Beanie Document classes at runtime from your DomainModel subclasses — no hand-written Document models needed. Requires varco-core.


Install

pip install varco-beanie

Requirements

  • Python ≥ 3.12
  • MongoDB ≥ 4.0
  • For multi-document transactions: a MongoDB replica set or sharded cluster

Features

  • Zero-boilerplate ODMBeanieModelFactory generates Document subclasses at runtime from your DomainModel classes; no duplication
  • Full repositoryAsyncBeanieRepository implements AsyncRepository (CRUD, exists(), stream_by_query())
  • Unit of WorkBeanieUnitOfWork wraps Motor session lifecycle with optional transactions
  • One-liner bootstrapBeanieRepositoryProvider + BeanieFastrestApp wire everything including init_beanie()
  • Query integration — accepts varco-core QueryParams / QueryBuilder AST natively

What's in the package

Module Purpose
factory.py BeanieModelFactory — generates Document subclasses; BeanieDocRegistry — escape hatch to access the generated Document
repository.py AsyncBeanieRepository — Motor-backed CRUD + exists() + stream_by_query()
uow.py BeanieUnitOfWork — Motor session lifecycle (optional transactions)
provider.py BeanieRepositoryProvider — wires factory + repos + UoW + init_beanie()
bootstrap.py BeanieConfig, BeanieFastrestApp — one-liner app setup

Quick start

Bootstrap (one-liner)

from motor.motor_asyncio import AsyncIOMotorClient
from varco_beanie import BeanieConfig, BeanieFastrestApp

client = AsyncIOMotorClient("mongodb://localhost:27017")

app = BeanieFastrestApp(BeanieConfig(
    motor_client=client,
    db_name="myapp",
    entity_classes=(User, Post),
))

await app.init()                    # calls beanie.init_beanie() internally
uow_provider = app.uow_provider     # ready to inject as IUoWProvider

Manual setup

from varco_beanie import BeanieRepositoryProvider

provider = BeanieRepositoryProvider(motor_client=client, db_name="myapp")
provider.register(User, Post)
await provider.init()

async with provider.make_uow() as uow:
    user = await uow.users.save(User(name="Edo", email="edo@example.com"))
    print(user.pk)

Transactions (replica set required)

provider = BeanieRepositoryProvider(
    motor_client=client,
    db_name="myapp",
    transactional=True,   # wraps each UoW in a Motor session transaction
)

Query integration

from varco_core import QueryBuilder, QueryParams

async with provider.make_uow() as uow:
    # exists() — uses .count(), no document load
    if await uow.posts.exists(post_id):
        ...

    # stream_by_query() — Motor batches internally, bounded memory
    params = QueryParams(node=QueryBuilder().eq("published", True).build())
    async for post in uow.posts.stream_by_query(params):
        await process(post)

Access the generated Beanie Document (escape hatch)

from varco_beanie import BeanieDocRegistry

PostDoc = BeanieDocRegistry.get(Post)
# use PostDoc for Beanie-specific operations not exposed by the repository

Notes

  • CheckConstraint entries in varco-core metadata are silently ignored — MongoDB has no SQL CHECK constraints. Use Pydantic validators instead.
  • Foreign key hints are metadata only — MongoDB has no FK enforcement.
  • Composite PKs are emulated via compound unique indexes; find_by_id(pk_tuple) issues a find_one with a composite filter.

Related packages

Package Description
varco-core Domain model, service layer, query AST, JWT — required dependency
varco-sa SQLAlchemy async backend (alternative to this package)

Links

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

varco_beanie-1.1.1.tar.gz (110.2 kB view details)

Uploaded Source

Built Distribution

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

varco_beanie-1.1.1-py3-none-any.whl (82.0 kB view details)

Uploaded Python 3

File details

Details for the file varco_beanie-1.1.1.tar.gz.

File metadata

  • Download URL: varco_beanie-1.1.1.tar.gz
  • Upload date:
  • Size: 110.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for varco_beanie-1.1.1.tar.gz
Algorithm Hash digest
SHA256 b947968e41d59a961a10b458ca9e8c7c0a78479b088b4a9d9f9d15f6626344e5
MD5 552f19fefba3918312d07c65165e9ec4
BLAKE2b-256 462a21e8c19cb5e687abed2ab51c8170bbc9d4945801c6244cdb79a9d45ecca7

See more details on using hashes here.

File details

Details for the file varco_beanie-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: varco_beanie-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 82.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for varco_beanie-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c665592581c098df74cf385510c35264312ec6d5e4fda454acbdea899c7f4e8d
MD5 3f5bf0213ed040ab18cad9003f58e76d
BLAKE2b-256 68bb4f9bf2442e67faf9bb0ee8bfeb308166674622a15cd3549e008bda8ac26f

See more details on using hashes here.

Release history Release notifications | RSS feed

3.2.0

2 files

3.1.0

2 files

3.0.0

2 files

This release

1.1.1 This release

2 files

1.1.0

2 files

1.0.6

2 files

0.1.0

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page