omni_api is a payload adaptation layer for platform teams that need to enforce backend API contracts while supporting heterogeneous upstream producers.
Requires Python 3.11+.
pip install omni-api-transformerOptional with uv:
uv add omni-api-transformerfrom omni_api import transform
source_payload = {
"full_name": "John Doe",
"age": 30,
"contact": {"email": "john@example.com"},
"extra_data": "ignored",
}
target_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"age": {"type": "number"},
"email": {"type": "string"},
},
"required": ["name", "age", "email"],
}
result = transform(source_payload, target_schema)
print(result.payload)
# {'name': 'John Doe', 'age': 30, 'email': 'john@example.com'}Inputs:
source_payload:dict[str, Any]target_schema: JSON Schema object subset (type,properties,required)
Returns TransformResult:
payload: transformed payload restricted to target schema keysplan: deterministic transform plan with mapping decisionsreport: mapped/dropped/missing fields and warnings
Raises:
TransformSchemaError: unsupported schema shapeTransformValidationError: missing required or invalid output payload
omni_api follows a deterministic two-step model:
- Compile a Transform Plan from source payload plus target contract.
- Execute that plan with a pure transformation step.
Core components:
- Router: selects target backend profile/route (future extension)
- Schema Loader: loads canonical backend contract
- Planner: generates deterministic mappings
- Executor: applies
mappings,defaults, anddrops - Validator: enforces required fields and output constraints
- Diagnostics: emits structured transformation report
flowchart LR
init["__init__.py"] --> api["api.py"]
api --> planner["planner.py"]
api --> executor["executor.py"]
api --> validator["validator.py"]
api --> errors["errors.py"]
api --> types["plan_types.py"]
planner --> types
executor --> types
- Backend contracts should be maintained as JSON Schema under
schemas/<provider>/<endpoint>.json. - Transform Plan DSL includes
mappings,defaults,drops,required. - Output keys are constrained to schema-defined keys in strict mode.
Run tests with uv:
cd python
uv run pytest -qBuild package artifacts:
cd python
uv run --with build python -m buildPublishing is automated via GitHub Actions (.github/workflows/ci-publish.yml):
- Push to
mainruns tests and then attempts PyPI publish - Publish uses GitHub secret
PYPI_API_TOKEN - Bump
python/pyproject.tomlversion before merge tomainto avoid duplicate version failures