Gault
A lightweight Object Document Mapper (ODM) for MongoDB with Python type hints and state tracking.
Features
- Type-safe MongoDB documents with Python type hints
- Field aliasing for database column mapping
- Query operators with Pythonic syntax
- Async and sync managers for CRUD operations
- Aggregation pipeline support with fluent API
- Automatic state tracking and dirty field detection
- Atomic updates with persistence tracking
Installation
pip install gault
Quick Start
from gault import Schema, Model, Field, configure, AsyncManager
# Schema: Persistent documents mapped to MongoDB collections
class Person(Schema, collection="people"):
id: Field[int] = configure(pk=True)
name: Field[str]
age: Field[int] = configure(db_alias="person_age")
# Model: Non-persistent data classes (projections, view models, etc.)
class PersonSummary(Model):
name: Field[str]
total: Field[int]
# Create manager
manager = AsyncManager(database)
# Query and modify
person = await manager.get(Person, filter=Person.id == 1)
person.age = 43
await manager.save(person, atomic=True) # Only updates dirty fields
Querying
# Comparison operators
Person.age >= 18
Person.id.in_([1, 2, 3])
# Logical operators
filter = (Person.age >= 18) & (Person.name == "Alice")
filter = (Person.name == "Alice") | (Person.name == "Bob")
filter = ~(Person.age < 18)
# Field expressions
Person.score.expr.gt(42)
Person.price.expr.gt(Person.discount_price)
Aggregation Pipelines
from gault import Pipeline
from gault.accumulators import Sum, Avg
pipeline = (
Pipeline()
.match(Person.age >= 18)
.group({"total": Sum(1), "avg_age": Avg("$age")}, by="$name")
.sort({"total": -1})
.take(10)
)
async for result in manager.select(PersonSummary, pipeline):
print(result.name, result.total)
Persistence & Dirty Fields
person = await manager.get(Person, filter=Person.id == 1)
person.name = "New Name"
person.age = 50
# Only updates changed fields
await manager.save(person, atomic=True)
Requirements
- Python >= 3.11
- PyMongo >= 4.15.4
Documentation
Full documentation available at johnnoone.github.io/gault.
License
MIT
Metadata
Release files for gault 0.14.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gault-0.14.0.tar.gz | 39.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gault-0.14.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 84.9 kB
Release files / gault-0.14.0.tar.gz
| Download URL | gault-0.14.0.tar.gz |
|---|---|
| Size | 39.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c03cae0ec759390d291b5dc92fa2fdc448734c027fa21352ce89b1a6343e8884
|
|
BLAKE2b-256 checksum How to use checksums |
8473dea44ead32f37191875dd26f0e54816bcf585eb60683d43d3589f9f0b1ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / gault-0.14.0-py3-none-any.whl
| Download URL | gault-0.14.0-py3-none-any.whl |
|---|---|
| Size | 45.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9822658e5522b3c9728b7c8144ca08cd8605ac8ada3363a6491dbc1be900aef9
|
|
BLAKE2b-256 checksum How to use checksums |
3097c4c80dd561b22416626c9aca3994684af4cea07eac744708c57e4178ac69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|