Skip to main content

apilize-protocol — Python SDK for the Apilize Protocol v1

Author financial-modeling containers that speak the Apilize Protocol v1 over CLI stdio. Subclass Model, override the handlers you need, ship a Docker container — the SDK takes care of the session loop, JSON-Lines framing, error envelopes, and exit codes.

Install

pip install apilize-protocol

Hello, Apilize — a complete model in ~30 lines

# model/handlers.py
from apilize_protocol import Model

class HelloValuation(Model):
    def _compute(self, inputs):
        """Pure calculation shared by handle_run and handle_export."""
        years = inputs["assumptions"]["holding_period_years"]
        annual = sum(u["monthly_rent_eur"] for u in inputs["units"]) * 12
        return {
            "cash_flows": [annual] * years,
            "npv": annual * years,
            "irr": 0.0,
            "terminal_value": 0.0,
        }

    def handle_run(self, msg):
        yield {"type": "progress", "stage": "summing", "percent": 50}
        yield {"type": "result", "data": self._compute(msg["input"])}

    def handle_export(self, msg):
        import json
        from pathlib import Path
        out = Path(msg["outputPath"])
        out.write_text(json.dumps(self._compute(msg["input"])))
        return {
            "format": msg["format"],
            "outputPath": str(out),
            "byteSize": out.stat().st_size,
        }
# model/__main__.py
import sys
from .handlers import HelloValuation

if __name__ == "__main__":
    sys.exit(HelloValuation.main())

Then add a data/spec.yaml, data/ui.yaml, data/i18n/en.yaml, copy the Dockerfile.template from this SDK as Dockerfile, and docker build — that's a conformant Apilize Protocol model.

What you get from Model

Method Default behavior Override when
handle_spec Returns the contents of data/spec.yaml You compute spec dynamically
handle_ui Returns data/ui.yaml You build UI from inputs
handle_i18n Returns data/i18n/{locale}.yaml; raises UnsupportedLocaleError if missing You source translations elsewhere
handle_validate Runs jsonschema validation against spec.inputSchema Domain-specific validation rules
handle_run Raises NotImplementedError Always — this is your model
handle_export Raises NotImplementedError If your spec declares export formats

The session loop, SIGTERM handling, exit-code semantics, JSON-Lines framing, per-message error wrapping, and validation are handled by Model.serve() (invoked via Model.main()).

Container packaging

Copy Dockerfile.template from this SDK into your model repo as Dockerfile. The template:

  • Uses python:3.12-slim as base.
  • Sets PYTHONUNBUFFERED=1 — required for the session-mode transport to work correctly. Without this, the orchestrator's readline() deadlocks.
  • Installs your pyproject.toml (which declares apilize-protocol as a dep).
  • Sets ENTRYPOINT ["python", "-m", "model"].

There is no published base image in v1.x; the template is the contract.

Note on the in-repo example Dockerfiles. The Dockerfiles under examples/dcf-example/ and examples/hello-valuation/ install the SDK from the repository's sdk/python/ source via COPY sdk/python /tmp/sdk rather than from PyPI. This is a repo-local-CI convenience — the SDK isn't published to PyPI yet, and the examples need to build against the in-tree source. External authors should use the template above, which installs from pip install . against their pyproject.toml that declares apilize-protocol as a regular dependency. The in-repo example divergence is internal to this repository's CI.

Conformance

The full conformance suite lives in apilize-protocol/conformance/. Run it against your container:

docker build -t my-model .
DOCKER_IMAGE=my-model pytest conformance/tests/

If all tests pass, your container is a conformant Apilize Protocol v1 model.

Optional: logging

The SDK does not own a logging convention beyond "stderr is empty on clean session" (per the protocol contract). If you want diagnostics in container logs during development:

import logging, sys
logging.basicConfig(stream=sys.stderr, level=logging.INFO)

Note that conformance asserts STDERR is empty on clean session exit — disable logging or redirect to a file before running conformance.

Public API

from apilize_protocol import (
    Model,                      # subclass this to write a model
    Kind,                       # Enum: VALUATION / SOURCE / TRANSFORM
    SpecResponse, UiResponse, I18nResponse,
    ValidateResponse, ValidationError,
    RunProgress, RunResult,
    ExportResponse,
    ProtocolError,
    ApilizeProtocolError,       # base exception
    UnsupportedLocaleError,
    UnsupportedFormatError,
    InputValidationError,
    MissingFieldError,
    DEFAULT_PROTOCOL_RANGE,     # "^1.0"
)

License

MIT. See LICENSE in the repository root.

Versioning

SDK versions track protocol minor versions: 1.1.0 SDK targets protocol 1.1.0. SDK-internal additive changes bump the SDK patch version while keeping the protocol target. Breaking changes require a new protocol major (v2) and a corresponding SDK major.

Release files for apilize-protocol 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apilize-protocol 1.1.0
File Size Uploaded
apilize_protocol-1.1.0.tar.gz 26.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apilize-protocol 1.1.0
File Interpreter ABI Platform
apilize_protocol-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.5 kB

Release files / apilize_protocol-1.1.0.tar.gz

Download URL apilize_protocol-1.1.0.tar.gz
Size 26.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b757c35cfc25f64143b13550112f31051f23d396d23f2dba485097d3122fe218
BLAKE2b-256 checksum
How to use checksums
9f940615ea4aca7877445fa58da833ebe8ac7e503c248e90732530e6400ab42f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2026.

Transparency log

Release files / apilize_protocol-1.1.0-py3-none-any.whl

Download URL apilize_protocol-1.1.0-py3-none-any.whl
Size 25.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4be6ffa8d657fe8def7a2ea2240bc8ba614f8f67e94ccc3607c22b4dc7abab82
BLAKE2b-256 checksum
How to use checksums
558dba4b66532dfc2c708e8d5bc9e75b1c9a2cf8cad0d9f33398006e10362621
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 12, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page