Skip to main content

MongoDB persistence for Pydantic AntDocs with a Mongo-like query DSL.

Project description

Antonic ant infrastructure logo

antonic

MongoDB persistence for Pydantic v2 AntDocs.

Antonic 0.1.1b1 is a beta pre-release. The public package is named antonic, while the core model and metadata classes keep the Ant vocabulary: AntDoc, AntConnector, AntIndex, ant_collection, and ant_indexes.

Install

pip install antonic

To install the current beta pre-release explicitly:

pip install antonic==0.1.1b1

Pre-release versions are not selected by plain pip install antonic when a stable release is available. To allow pip to consider beta releases:

pip install --pre antonic

AntDocs describe data and local persistence metadata. AntConnector owns the MongoDB connection and document behavior:

from typing import ClassVar, Sequence

from antonic import ASCENDING, DESCENDING, AntConnector, AntDoc, AntIndex


class User(AntDoc):
    email: str
    name: str
    status: str = "active"

    ant_collection: ClassVar[str] = "users"
    ant_indexes: ClassVar[Sequence[AntIndex]] = (
        AntIndex([("email", ASCENDING)], unique=True, name="uniq_user_email"),
        AntIndex([("status", ASCENDING), ("created_at", DESCENDING)]),
    )


class Project(AntDoc):
    owner_id: str
    slug: str
    title: str

    # Collection defaults to "projects".
    ant_indexes: ClassVar[Sequence[AntIndex]] = (
        AntIndex([("owner_id", ASCENDING), ("slug", ASCENDING)], unique=True),
    )


async def main() -> None:
    async with AntConnector("mongodb://localhost:27017/app") as db:
        await db.ensure_indexes(User, Project)

        user = await db.save(User(email="a@b.com", name="Alice"))
        found = await db.get(User, user.id)
        active = await db.find(User, status="active", sort=[("created_at", -1)], limit=25)

        await db.patch(User, {"name": "Alice Cooper"}, id=user.id)
        await db.delete(user)

        raw_users = db.collection(User)
        await raw_users.find_one({"email": "a@b.com"})

If no connection string is passed, AntConnector() reads MONGODB_URI. The database name can come from the URI path, from database=, or from MONGODB_DATABASE when the URI has no database path.

filter={...} accepts Ant's Mongo-like query DSL. Extra keyword arguments are equality filters, so use filter={"limit": 10} for document fields that collide with connector options.

Plain AntDoc ids default to MongoDB ObjectId values. You can pass either an ObjectId or its string form to connector methods that filter by id.

Antonic requires Python 3.12 or newer.

License

Apache-2.0. See LICENSE.

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

antonic-0.1.1b1.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

antonic-0.1.1b1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file antonic-0.1.1b1.tar.gz.

File metadata

  • Download URL: antonic-0.1.1b1.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for antonic-0.1.1b1.tar.gz
Algorithm Hash digest
SHA256 ae5746b6892fac01e86e0a32967836296ec45310b7208ae07f7ee6c39c6c80f9
MD5 12c733bb0be268344fbd9a19fa741f9b
BLAKE2b-256 9be83b46daabede64e390bb4c52802daf6b83fed2a60f8fc976d1a065afdea2d

See more details on using hashes here.

Provenance

The following attestation bundles were made for antonic-0.1.1b1.tar.gz:

Publisher: release.yml on oryacobi/antonic

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

File details

Details for the file antonic-0.1.1b1-py3-none-any.whl.

File metadata

  • Download URL: antonic-0.1.1b1-py3-none-any.whl
  • Upload date:
  • Size: 17.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for antonic-0.1.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 89f349620c5c21a1c70f784f90eb69b01dc5ade4ae56626925dc7bee89b4b518
MD5 64524320612a99d84ed936e610befdd2
BLAKE2b-256 c5aac086404ac1b3be4a4f295a1ae9f459640c1ea833dc659a6f6771d09e727b

See more details on using hashes here.

Provenance

The following attestation bundles were made for antonic-0.1.1b1-py3-none-any.whl:

Publisher: release.yml on oryacobi/antonic

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