Momoa
A library for definition, validation and serialisation of models based on JSON Schema specifications.
Basic Usage
StathamEngine (default)
from datetime import datetime
from momoa import Schema
from momoa.engines.statham import UNDEFINED
schema = Schema.from_uri("file://path/to/schema.json")
PersonModel = schema.model
person = PersonModel(firstName="Boris", lastName="Harrison")
# Unset optional fields return UNDEFINED
assert person.age is UNDEFINED
# Fields can be set after instantiation
person.age = 53
person.birthday = datetime(1969, 11, 23)
assert person.age == 53
assert person.serialize()["birthday"] == "1969-11-23"
PydanticEngine
from momoa import Schema
from momoa.engines.pydantic import PydanticEngine
schema = Schema.from_uri("file://path/to/schema.json", engine=PydanticEngine())
PersonModel = schema.model # a pydantic.BaseModel subclass
person = PersonModel(firstName="Boris", lastName="Harrison", age=53)
# Unset optional fields return None
assert person.birthday is None
# Serialize omits unset fields
serialized = person.serialize()
assert serialized["firstName"] == "Boris"
assert "birthday" not in serialized
# Pydantic's native API is also available
person.model_dump(exclude_unset=True)
PersonModel.model_validate({"firstName": "Alice", "lastName": "Smith"})
Engine Selection
Momoa compiles schemas through a pluggable engine. The default is StathamEngine.
To use Pydantic v2 BaseModel subclasses instead, pass engine= explicitly:
from momoa import Schema
from momoa.engines.pydantic import PydanticEngine
schema = Schema.from_file("path/to/schema.json", engine=PydanticEngine())
person = schema.deserialize({"firstName": "Alice", "lastName": "Smith"})
print(person.model_dump()) # standard Pydantic API also available
The active engine can also be set via the MOMOA_DEFAULT_ENGINE environment variable
(statham or pydantic), which is useful for switching without changing code.
Compatibility
Momoa supports two engines with different JSON Schema draft coverage:
| Engine | Backend | JSON Schema drafts |
|---|---|---|
StathamEngine (default) |
Statham | Draft 6 |
PydanticEngine |
datamodel-code-generator + Pydantic v2 | Draft 4 – 2020-12 |
Metadata
Release files for momoa 0.4.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 | Provenance | Actions |
|---|---|---|---|---|
| momoa-0.4.0.tar.gz | 83.6 kB | Without provenance | Details for momoa-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| momoa-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for momoa-0.4.0-py3-none-any.whl |
Total release size: 93.1 kB
Release files / momoa-0.4.0.tar.gz
| Download URL | momoa-0.4.0.tar.gz |
|---|---|
| Size | 83.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ac01af5c54ba3d2a81fceaddb32485144737f4c488509dfb7e03b16409e2deb
|
|
BLAKE2b-256 checksum How to use checksums |
e0eef003aba6d6371bf379a9d71b9bd55494c76c4a8d32e9680722b3751e7c01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / momoa-0.4.0-py3-none-any.whl
| Download URL | momoa-0.4.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
888476379e82f35d7ba7aab1a1892422c47ae766093f41e0f1172ea5a181a5f8
|
|
BLAKE2b-256 checksum How to use checksums |
90f3a8f73afb45073049bb64226c813053ff3d3704b2dceb33d48a096908950e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for momoa 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.