Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Epistola Python Client

Python client library for the Epistola document generation API, generated from the Epistola OpenAPI contract with OpenAPI Generator (python / urllib3, pydantic v2 models).

It adds, on top of the stock generated client:

  • Client identity headers (User-Agent + X-EP-Node-Id) required on every request.
  • RFC 9457 problem-detail error handling — typed ProblemDetailException with a type_slug discriminator and generated KnownProblemSlugs constants.
  • Static API-key authentication via Authorization: ApiKey <key>, the supported method.
  • Self-signed JWT authentication (JwtSigner, experimental), minting a fresh short-lived token per request.
  • NDJSON result collection (ResultCollector) with adaptive polling, compression, and partition-aware routing helpers.
  • Template data validation (TemplateSchemaValidator), asking the server, with a pluggable TemplateDataValidator for consumers who want the check in-process.

The package version tracks the Epistola contract version (info.version) and releases in lockstep with the Kotlin and .NET clients.

Install

pip install epistola-client

Prerelease snapshots (published on every push to main) are available from TestPyPI:

pip install -i https://test.pypi.org/simple/ \
  --extra-index-url https://pypi.org/simple/ epistola-client

Quick start

from epistola_client import (
    EpistolaClientBuilder, ClientIdentity, TemplatesApi,
)

identity = ClientIdentity.builder().node_id("my-pod-123").build()

http = (
    EpistolaClientBuilder()
    .base_url("https://epistola.example.com/api")
    .identity(identity)
    .api_key("epk_...")
    .install_problem_detail_handler()
    .build()
)

templates = TemplatesApi(http)
# tenant, catalog registry ("~" = the server's default), namespace, key, release, template
template = templates.get_template("acme", "~", "acme", "invoices", "1.4.0", "invoice")

Everything in a catalog is addressed through one of its releases, by its release_id or, once released, by its exact version: a release keeps its id and its name when it is released. A catalog can have any number of drafts, and a draft gets its version when it is released. CatalogsApi lists and reads those releases (list_catalog_releases, get_catalog_release), starts drafts (create_catalog_release, from a release or another draft), updates (update_catalog_release) and discards (delete_catalog_release) them, and previews and releases any of them (preview_catalog_draft_release, release_catalog_draft).

.api_key(...) sends Authorization: ApiKey <key>. Some Epistola Suite deployments may disable API-key authentication entirely; with .install_problem_detail_handler(), switch on e.type_slug == KnownProblemSlugs.API_KEY_AUTH_DISABLED and guide the caller to JWT auth.

Self-signed JWT authentication is experimental: Epistola Suite may not implement it yet, and the flow may still change. To try it, pass .jwt_signer(signer) instead of .api_key(...):

from epistola_client import JwtSigner

signer = (
    JwtSigner.builder()
    .consumer_id("invoice-service")
    .private_key(JwtSigner.load_private_key("private.pem"))
    .build()
)

Error handling

Install the opt-in problem-detail handler on the client (.install_problem_detail_handler()), then switch on type_slug against KnownProblemSlugs. The slug list is open — the API can introduce new problem types without a client release — so always keep a fallback branch and fall back to the HTTP status for unrecognized types.

from epistola_client import (
    TenantsApi, ProblemDetailException, KnownProblemSlugs,
)

try:
    tenants_api.get_tenant("acme")
except ProblemDetailException as e:
    match e.type_slug:
        case KnownProblemSlugs.NOT_FOUND:
            log.warning("tenant not found: %s", e.detail)
        case KnownProblemSlugs.FORBIDDEN:
            raise PermissionError(e.detail)
        case KnownProblemSlugs.VALIDATION_ERROR:
            for err in e.errors:               # field-level ValidationProblemDetail
                log.warning("%s: %s", err.var_field, err.message)
        case KnownProblemSlugs.DATA_MODEL_VALIDATION_ERROR:
            for example, failures in e.validation_errors.items():  # 422 data-model failures
                for f in failures:
                    log.warning("%s %s: %s", example, f.path, f.message)
        case KnownProblemSlugs.RELEASE_DEPENDENCIES_MISSING:
            for d in e.missing_dependencies:   # 409 from deploy_catalog_release
                log.warning("%s/%s/%s@%s: %s", d.registry, d.namespace,
                            d.catalog_key, d.version, d.reason)
        case KnownProblemSlugs.RELEASE_DEPENDENCIES_UNRELEASED:
            for d in e.unreleased_dependencies:  # 409 from release_catalog_draft
                log.warning("%s/%s/%s uses draft %s (%s)", d.registry, d.namespace,
                            d.catalog_key, d.release_name, d.release_id)
        case KnownProblemSlugs.CATALOG_READ_ONLY:
            # any write to a catalog that cannot be changed here
            log.warning("catalog cannot be changed here: %s", e.read_only_reason)
        case KnownProblemSlugs.MERGE_CONFLICTS_UNRESOLVED:
            for conflict in e.unresolved_conflicts:  # merge_into_catalog_draft (alpha)
                log.warning("needs ours or theirs: %s", conflict)
        case KnownProblemSlugs.MERGE_PREVIEW_OUTDATED:
            # expected_token named a preview, and the draft or the release changed since
            log.warning("preview the merge again")
        case KnownProblemSlugs.MERGE_BASE_MISSING:
            # the merge base is not installed here: install that release first
            log.warning("install %s (%s) first", e.missing_base_version, e.missing_base_fingerprint)
        case KnownProblemSlugs.CATALOG_RENDERING_DEFAULTS_TOO_NEW:
            # import_catalog / install_catalog_release: the release renders with rendering
            # defaults this installation does not have (renderingDefaultsVersion, supportedVersion)
            log.warning("upgrade Epistola to receive this release")
        case KnownProblemSlugs.RELEASE_NUMBER_TAKEN:
            # publish_release_to_registry (alpha): the registry has this version with other content;
            # import_catalog, install_catalog_release, install_registry_release: the tenant has this
            # version with another fingerprint, or this release id as another release
            log.warning("release the changes under a new version")
        case KnownProblemSlugs.CATALOG_SOURCE_UNAVAILABLE:
            # install_catalog_release / list_available_catalog_releases: 503 when the catalog's
            # source could not be reached (Retry-After may say when), 502 when it answered badly
            log.warning("catalog source unavailable (%s): %s", e.problem_status, e.detail)
        case _:
            raise                              # unknown / framework error — fall back to status

ProblemDetailException extends the generated ApiException, so existing except ApiException sites keep working. It exposes type, type_slug, title, problem_status, detail, errors, validation_errors, missing_fields, invalid_fields, missing_dependencies, unreleased_dependencies, is_validation_problem, is_data_model_validation_problem, is_template_data_problem, is_release_dependencies_missing_problem and is_release_dependencies_unreleased_problem. Each missing_dependencies entry is a MissingDependency whose reason is the wire string, so a reason a later contract adds is reported rather than lost. Each unreleased_dependencies entry is an UnreleasedDependency(registry, namespace, catalog_key, release_id, release_name): a draft of another catalog to release first, or along with the release (releaseDependencies).

Result collection

from epistola_client import ResultCollector

collector = (
    ResultCollector.builder()
    .api_client(http)
    .tenant_key("acme")
    .handler(lambda result: print(
        result.request_id,
        result.status,  # "completed" or "failed", as sent
        # The catalog it was generated from; version is None when rendered from a draft.
        f"{result.registry}/{result.namespace}/{result.catalog_key}@{result.version}",
    ))
    .build()
)
collector.start()   # blocks; adaptive polling until collector.stop()

Response headers

Each operation has a …_with_http_info variant that returns the response headers next to the parsed body. Updates that take if_match answer with the new ETag, and a stale one is refused with 412 (KnownProblemSlugs.RESOURCE_MODIFIED); a create answers with the Location of what it made:

from epistola_client import EnvironmentsApi, UpdateEnvironmentRequest

environments = EnvironmentsApi(http)
current = environments.get_environment_with_http_info("acme", "staging")
updated = environments.update_environment_with_http_info(
    "acme", "staging", UpdateEnvironmentRequest(name="Staging"),
    if_match=current.headers["ETag"],
)

Uploading files

Multipart operations such as upload_image and import_catalog take the file as a (filename, bytes) pair. The part's content type is guessed from the filename's extension:

from epistola_client import ImagesApi

with open("logo.png", "rb") as f:
    image = ImagesApi(http).upload_image(
        "acme-corp", "~", "acme-corp", "main", "k7m2x9qa",
        ("logo.png", f.read()), name="Logo"
    )

A catalog is addressed by its registry, namespace and key — here the server's default registry ~, namespace acme-corp, key main — and an image belongs to one of its releases, here the draft with that id. A registry other than the default is named in full (exchange.example.org, acme.com). In a request body, leave registry unset for the default registry; responses always name it in full.

Bare bytes are sent with the field name, file, as their filename and with type application/octet-stream. The server then names the image file, and rejects it as not an image unless you also pass media_type.

Development

The client is generated from the bundled spec. From the repository root:

make bundle                       # produce openapi.yaml
cd contracts/api/clients/python-urllib3
./generate.sh                     # stock client + derived sources
uv run pytest                     # run the tests

generated/ (stock client) and src/epistola_client/_generated/ (derived sources) are gitignored and rebuilt from the spec each time.

Metadata

Release files for epistola-client 2.0.0a1

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

Source distribution (sdist)

Source distribution for epistola-client 2.0.0a1
File Size Uploaded Provenance Actions
epistola_client-2.0.0a1.tar.gz 493.5 kB With provenance Details for epistola_client-2.0.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for epistola-client 2.0.0a1
File Interpreter ABI Platform Actions
epistola_client-2.0.0a1-py3-none-any.whl Python 3 none any Details for epistola_client-2.0.0a1-py3-none-any.whl

Total release size: 2.3 MB

Release files / epistola_client-2.0.0a1.tar.gz

Download URL epistola_client-2.0.0a1.tar.gz
Size 493.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9d4cbfae3351b27e3b59fb9d1d5e0100d1c4ee0f2097e3b062b9a798eda2622d
BLAKE2b-256 checksum
How to use checksums
684d7c2fe60b2f905e0dd9a4c1945c82fa2bac006641b4f7c8096308ff056490
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 23, 2026.

Transparency log

Release files / epistola_client-2.0.0a1-py3-none-any.whl

Download URL epistola_client-2.0.0a1-py3-none-any.whl
Size 1.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
d155f0af1826dd44a9a42b4d75f61f83cb7ae60489e418963b8b57a838037112
BLAKE2b-256 checksum
How to use checksums
9b01cf2f76daac53b94185d0fc23a984ed3115f17e601801236fa94eb3908915
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Oct 23, 2026.

Transparency log

Security for epistola-client 2.0.0a1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for epistola_client-2.0.0a1.tar.gz

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 Oct 23, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release
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