jsonprofile for Python
Python implementation of jsonprofile for validating JSON documents against JSON Schemas and domain-specific JSON Profiles.
Requires Python 3.10 or later (tested on Python 3.10 through 3.14).
Installation
Standard Installation
pip install jsonprofile
# or with uv:
uv add jsonprofile
With Optional OPA WASM Extension
Local Open Policy Agent (OPA) WASM policy evaluation is provided as an optional extra (jsonprofile[opa]):
pip install "jsonprofile[opa]"
# or in a development workspace:
uv sync --extra opa --group dev
Core API Overview
| Class / Function | Module | Description |
|---|---|---|
JsonValidator |
jsonprofile.validator |
Main validator engine. Accepts a JSON Schema (str, Path, dict, or None), a target profile (str, Path, dict, or JsonProfile), and optional referenced_profiles, default_cv_term_search, and opa_engine_factory. |
JsonProfile |
jsonprofile.profile.model |
Pydantic model representing a JSON Profile (id, version, name, extends, configuration, requirements). |
ValidationRuntimeConfiguration |
jsonprofile.profile.base |
Per-run settings (offline_mode, skip_jsonschema_validation, skip_profile_validation, skip_decimal_validations, skipped_requirements, max_messages_for_each_requirement). |
JsonValidationResult |
jsonprofile.validator.context |
Validation output containing errors, recommendations, and optionals (each dict[str, list[JsonProfileMessage]] keyed by JSONPath). |
validate_profile_file |
jsonprofile.profile.profile_validator |
Validates a profile JSON file against jsonprofile.schema.json and checks structural rules (unique requirement codes, valid JSONPath expressions). |
Usage Examples
1. Basic Usage (Validating a JSON File or Dictionary)
from pathlib import Path
from jsonprofile.profile.base import ValidationRuntimeConfiguration
from jsonprofile.validator import JsonValidator
validator = JsonValidator(
json_schema=Path("../shared/resources/mztab-m/mztabm-2.1.0-M.schema.json"),
profile=Path(
"../shared/resources/mztab-m/profiles/mztabm-default-profile-2.1.0-M.json"
),
)
runtime_config = ValidationRuntimeConfiguration(
offline_mode=True,
skip_jsonschema_validation=False,
max_messages_for_each_requirement=10,
)
result = validator.validate_json_file(
json_file_path="../shared/resources/mztab-m/manual_null_MTBLS263.mztab.json",
runtime_config=runtime_config,
)
for json_path, messages in result.errors.items():
for msg in messages:
print(f"[REQUIRED] {msg.code} ({json_path}): {msg.message}")
for json_path, messages in result.recommendations.items():
for msg in messages:
print(f"[RECOMMENDED] {msg.code} ({json_path}): {msg.message}")
2. Profile Inheritance (extends & referenced_profiles)
When a profile extends one or more parent profiles via "extends", pass the parent profiles (by ID -> file path, dict, or JsonProfile) in referenced_profiles:
from jsonprofile.validator import JsonValidator
DEFAULT_ID = "https://github.com/HUPO-PSI/mzTab-M/tree/main/schema/profiles/mztabm-default-profile-2.1.0-M.json"
MTBLS_ID = "https://github.com/HUPO-PSI/mzTab-M/tree/main/schema/profiles/mztabm-metabolights-profile-2.1.0-M.json"
referenced_profiles = {
DEFAULT_ID: "../shared/resources/mztab-m/profiles/mztabm-default-profile-2.1.0-M.json",
MTBLS_ID: "../shared/resources/mztab-m/profiles/mztabm-metabolights-profile-2.1.0-M.json",
}
validator = JsonValidator(
json_schema="../shared/resources/mztab-m/mztabm-2.1.0-M.schema.json",
profile=referenced_profiles[MTBLS_ID],
referenced_profiles=referenced_profiles,
)
OPA Extension Usage
jsonprofile supports evaluating compiled OPA WASM bundles (.wasm or .tar.gz bundles containing policy.wasm and data.json) in two ways:
OpaFieldRequirement: Defined directly underrequirementswith apolicy_idand optionalwasm_file_key.OpaPolicyConstraint(type: "opa-policy"): Defined inside aFieldRequirement'svalue_constraint.
Configuring OPA in a Profile
{
"id": "https://example.org/profiles/opa-profile.json",
"version": "1.0.0",
"name": "OPA-Enabled Profile",
"configuration": {
"default_wasm_file_key": "default",
"wasm_file_definitions": {
"default": {
"wasm_file_path": "../shared/resources/mztab-m/mztabm-default-2.1.0-M.wasm",
"wasm_file_download_url": "https://github.com/HUPO-PSI/mzTab-M/raw/refs/heads/development/mztab_m_io/resources/mztabm-default-2.1.0-M.wasm",
"entrypoint": "mztabm/policies"
}
}
},
"requirements": {
"$": {
"code": "D-0010",
"enforcement_level": "required",
"policy_id": "policy_d_0010"
}
}
}
Running with LocalOpaEngineFactory or Custom OpaEngineFactory
When jsonprofile[opa] (opa-wasmtime) is installed, JsonValidator automatically uses LocalOpaEngineFactory. You can also instantiate LocalOpaEngine directly or inject a custom OpaEngineFactory:
from typing import Optional
from jsonprofile.validator import JsonValidator
from jsonprofile.validator.opa_engine import OpaEngine, OpaEngineFactory
class CustomOpaEngine(OpaEngine):
def evaluate(
self,
input_data: dict,
entrypoint: Optional[str] = None,
data: Optional[dict] = None,
) -> dict:
# Custom or remote OPA evaluation returning {"messages": [...]}
return {"messages": []}
class CustomOpaEngineFactory(OpaEngineFactory):
def get_opa_engine(
self,
wasm_file_path: str,
wasm_file_download_url: Optional[str] = None,
) -> OpaEngine:
return CustomOpaEngine()
validator = JsonValidator(
json_schema=None,
profile="opa-profile.json",
opa_engine_factory=CustomOpaEngineFactory(),
)
Custom Validators & Constraint Checkers
You can register custom constraint checkers using @profile_validator and @constraint_checker:
from typing import Any, Optional, Tuple
from jsonprofile.profile.constraints import CustomConstraint
from jsonprofile.validator.abstract_checker import ConstraintChecker
from jsonprofile.validator.context import JsonProfileRunContext
from jsonprofile.validator.default_validator import (
DefaultProfileValidator,
constraint_checker,
profile_validator,
)
@profile_validator(label="my_domain", validator_id="my-domain-validator")
class MyDomainValidator(DefaultProfileValidator):
pass
@constraint_checker(
CustomConstraint,
constraint_name="accession_prefix",
validator_id="my-domain-validator",
)
class AccessionPrefixChecker(ConstraintChecker):
def validate(
self,
constraint: CustomConstraint,
value: Any,
root: dict[str, Any],
context: JsonProfileRunContext,
) -> Tuple[bool, Optional[str]]:
ok = isinstance(value, str) and value.startswith("ACC-")
return ok, self.format_message(constraint, "Must start with ACC-")
Development & Testing
# From repository root:
just format-python
just lint-python
just test-python
just build-python
# Or from python/ directory:
uv sync --extra opa --group dev
PYTHONPATH=. uv run pytest
Metadata
Release files for jsonprofile 0.2.2
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 |
|---|---|---|---|---|
| jsonprofile-0.2.2.tar.gz | 63.8 kB | Without provenance | Details for jsonprofile-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jsonprofile-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for jsonprofile-0.2.2-py3-none-any.whl |
Total release size: 136.6 kB
Release files / jsonprofile-0.2.2.tar.gz
| Download URL | jsonprofile-0.2.2.tar.gz |
|---|---|
| Size | 63.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4f35ba9d2ec1a4069601d4c7ab3004a8b3bd33fe9c4b26fc1cb2531323f69d2f
|
|
BLAKE2b-256 checksum How to use checksums |
68f6c8a8ad9368f57592cada3f31082d833dddb8b42b44ec2d213074ff23dafd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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 / jsonprofile-0.2.2-py3-none-any.whl
| Download URL | jsonprofile-0.2.2-py3-none-any.whl |
|---|---|
| Size | 72.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4074c2ac7b92dc5c9a780f669bd8a7ad3cc2c3b8e53dac1a9a030e6199973c2b
|
|
BLAKE2b-256 checksum How to use checksums |
c693c2b1bba4c6a8fb264578b37c93550fb7c4ad5482ce99218b524237665902
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","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 jsonprofile 0.2.2
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.