Skip to main content

Mongoz

Mongoz

Typed asynchronous MongoDB documents and queries for Python.

Test Suite Package version Supported Python versions

Mongoz is an asynchronous object-document mapper for MongoDB, built on native PyMongo Async and Pydantic. It combines typed documents, composable clone-on-write queries, deliberate persistence semantics, inspectable index reconciliation, sessions, transactions, aggregation, bulk writes, and direct native-driver escape hatches.

Installation

python -m pip install mongoz

Mongoz supports Python 3.10–3.14, PyMongo >=4.13,<5.0, and Pydantic 2. The package ships py.typed for PEP 561 consumers.

Quickstart

from mongoz import Boolean, Document, Registry, String

registry = Registry("mongodb://localhost:27017")


class User(Document):
    name: str = String(min_length=1, max_length=80)
    email: str = String(unique=True)
    active: bool = Boolean(default=True)

    class Meta:
        registry = registry
        database = "app"


async def main() -> None:
    async with registry:
        user = await User.objects.create(name="Ada", email="ada@example.com")

        found = await User.objects.get(id=user.id)
        active_users = await User.objects.filter(active=True).sort("name")

        await found.update(name="Ada Lovelace")
        await found.delete()

        assert active_users[0].email == "ada@example.com"

A Registry owns one PyMongo AsyncMongoClient. Reuse it for the application lifecycle and close it during shutdown; a closed Registry is final. Document declaration performs no database or index I/O.

Why Mongoz

  • Pydantic-backed Document and EmbeddedDocument models
  • familiar Manager filters and explicit Q/field expressions
  • immutable query derivation for safe reuse
  • atomic patch updates and explicit full-model save behavior
  • index planning before reviewed reconciliation
  • PyMongo Async sessions, transactions, aggregation, and bulk writes
  • deterministic async-only document signals
  • typed native client, database, collection, cursor, and session boundaries
  • security guidance for raw queries, regex, credentials, and destructive indexes

Mongoz does not replace PyMongo's ownership of topology, pooling, timeouts, retries, read/write concerns, native errors, or transaction lifecycle. Use registry.driver, database.driver, and collection.driver when the driver is the right abstraction.

Documentation

New users should begin with the Quickstart. Existing applications should review the migration guide. Production deployments should use the operations checklist and security guide.

Contributing and security

The contributor guide documents the Zensical documentation workflow, quality gates, real MongoDB topologies, typing checks, and package proof.

Report suspected vulnerabilities privately through the repository Security tab according to SECURITY.md, not through a public issue.

Metadata

Release files for mongoz 0.14.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mongoz 0.14.0
File Size Uploaded
mongoz-0.14.0.tar.gz 47.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mongoz 0.14.0
File Interpreter ABI Platform
mongoz-0.14.0-py3-none-any.whl Python 3 none any Details

Total release size: 114.9 kB

Release files / mongoz-0.14.0.tar.gz

Download URL mongoz-0.14.0.tar.gz
Size 47.7 kB
Tags Source
SHA-256 checksum
How to use checksums
60bea193c8e60059a040b348c7b50334bd79f7ad6a0b6f6ab4d452dc98bd927d
BLAKE2b-256 checksum
How to use checksums
bce1cd727194eddbb9f92b68e1562f7bc6b27952240da2fc490b3e0fe4c68b45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21

Release files / mongoz-0.14.0-py3-none-any.whl

Download URL mongoz-0.14.0-py3-none-any.whl
Size 67.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3535a0a0f1e94418a9749e635c5401e284ae9b4f8d50c255c7fbbca60dc5f5f3
BLAKE2b-256 checksum
How to use checksums
a41c4e571f3f8e6394f5b69dc3b62f52d5f04fd2ea0b7e96de36feb8098833a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.21
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