MongoDB persistence for Pydantic AntDocs with a Mongo-like query DSL.
Project description
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae5746b6892fac01e86e0a32967836296ec45310b7208ae07f7ee6c39c6c80f9
|
|
| MD5 |
12c733bb0be268344fbd9a19fa741f9b
|
|
| BLAKE2b-256 |
9be83b46daabede64e390bb4c52802daf6b83fed2a60f8fc976d1a065afdea2d
|
Provenance
The following attestation bundles were made for antonic-0.1.1b1.tar.gz:
Publisher:
release.yml on oryacobi/antonic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
antonic-0.1.1b1.tar.gz -
Subject digest:
ae5746b6892fac01e86e0a32967836296ec45310b7208ae07f7ee6c39c6c80f9 - Sigstore transparency entry: 1889558632
- Sigstore integration time:
-
Permalink:
oryacobi/antonic@1b7074bb2d1bceec33c155c11368f05456ae8a57 -
Branch / Tag:
refs/tags/v0.1.1b1 - Owner: https://github.com/oryacobi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1b7074bb2d1bceec33c155c11368f05456ae8a57 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
89f349620c5c21a1c70f784f90eb69b01dc5ade4ae56626925dc7bee89b4b518
|
|
| MD5 |
64524320612a99d84ed936e610befdd2
|
|
| BLAKE2b-256 |
c5aac086404ac1b3be4a4f295a1ae9f459640c1ea833dc659a6f6771d09e727b
|
Provenance
The following attestation bundles were made for antonic-0.1.1b1-py3-none-any.whl:
Publisher:
release.yml on oryacobi/antonic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
antonic-0.1.1b1-py3-none-any.whl -
Subject digest:
89f349620c5c21a1c70f784f90eb69b01dc5ade4ae56626925dc7bee89b4b518 - Sigstore transparency entry: 1889558729
- Sigstore integration time:
-
Permalink:
oryacobi/antonic@1b7074bb2d1bceec33c155c11368f05456ae8a57 -
Branch / Tag:
refs/tags/v0.1.1b1 - Owner: https://github.com/oryacobi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1b7074bb2d1bceec33c155c11368f05456ae8a57 -
Trigger Event:
release
-
Statement type: