Skip to main content

Tempo Worker SDK (Python)

A Tempo worker is a process that Tempo runs on its compute backends to execute tasks. A task is your own custom business logic, packaged as a function with this signature:

from pathlib import Path
from tempo_worker import WorkerContext

def run(working_dir: Path, params: dict, ctx: WorkerContext) -> None: ...

Tempo calls run with a working directory (inputs under working_dir/inputs/, outputs written to working_dir/outputs/), the job parameters, and a WorkerContext that carries execution-environment identifiers for the current attempt. Tempo creates the directory only when the job declares inputs or outputs. A job that declares neither gets a path that does not exist, and must create it before use. Task code needs no platform imports beyond the SDK, so you do not need anything else to write a task. The SDK gives you easy, standardised access to the job run context, structured logging, custom metrics, and failure reporting. fourtheorem-tempo-worker (import name tempo_worker) provides all of this.

pip install fourtheorem-tempo-worker

When you run task code yourself (locally, or in unit tests) instead of on a Tempo worker, this is a standalone run: the SDK detects it and falls back to the safe defaults noted in each section below.

Features

Here is the list of features you find in the SDK.

Run context

The harness passes a WorkerContext directly as the third argument to run. It carries execution-environment identifiers for the current attempt.

from pathlib import Path
from tempo_worker import WorkerContext

def run(working_dir: Path, params: dict, ctx: WorkerContext) -> None:
    print(ctx.workload_id, ctx.job_id, ctx.attempt, ctx.worker_id, ctx.resource_class)

The context object carries five properties:

  • workload_id: the workload the job belongs to.
  • job_id: the job the worker is executing.
  • attempt: the zero-based retry attempt number.
  • worker_id: the worker process running the job.
  • resource_class: the resource class serving this job (e.g. "default", "gpu").

current_context() provides the same object for helper code that cannot receive ctx as a parameter. In a standalone run, current_context() returns None; ctx is not available outside the harness.

Logging

get_logger returns a standard library logger that emits structured, single-line JSON records, ready for observability and monitoring tools. On a Tempo worker each record automatically carries workload_id, job_id, attempt, and worker_id, so you can filter and correlate task logs with the rest of the platform logs.

from tempo_worker import get_logger

logger = get_logger(__name__)

def run(working_dir, params, ctx):
    logger.info("Pricing started", extra={"scenario_count": len(params["scenarios"])})

In a standalone run the SDK installs a JSON handler with the same field shape, so log lines look identical in both environments. Standalone runs read the service name from TEMPO_SERVICE_NAME (default tempo-task) and the level from LOG_LEVEL (default INFO).

Custom metrics

The tempo_worker.metrics module provides counter, histogram, and up_down_counter. They create instruments that export through the worker's metrics pipeline. Tempo prefixes each name with tr_custom_ and attaches the workload_id label from the run context. The series appear in the Tempo Grafana dashboard under "Custom task metrics".

from tempo_worker import metrics

rows = metrics.counter("rows_processed", description="Rows processed per job.")
latency = metrics.histogram("pricing_seconds", unit="s")

def run(working_dir, params, ctx):
    rows.add(1_000)
    latency.record(2.31)

The attribute keys job_id and worker_id are rejected: their cardinality is unbounded and would overload the time-series store.

A standalone run has no configured metrics provider, so every call is a no-op.

A note on naming. You might have noticed that logging has a factory function, get_logger, while metrics is a module namespace. This is deliberate: each follows the strongest convention in its own domain. get_logger(__name__) mirrors the stdlib logging.getLogger(__name__) idiom, and metrics.counter(...) mirrors the OpenTelemetry module-style API. A logger is a stateful object you keep; the metrics functions are factories for named instruments.

Explicit failure reporting

Raise TaskFailure to report a failure with structured context. Set retriable=False to tell the scheduler not to retry the job, even when retry budget remains. Use it when a retry cannot change the outcome, for example corrupt input data or invalid parameters: every attempt would fail the same way, so skipping the retries saves time and compute, and the workload reaches its final state sooner.

The detail dict is stored in the job attempt record, so keep its values JSON-serialisable.

from tempo_worker import TaskFailure

def run(working_dir, params, ctx):
    if "rate_table" not in params:
        raise TaskFailure(
            "missing rate_table parameter",
            retriable=False,
            detail={"missing_field": "rate_table"},
        )

By default, any exception other than TaskFailure is reported as a retriable failure.

In a standalone run, TaskFailure is a plain exception and propagates normally.

Versioning

The SDK follows the Tempo platform release version.

Metadata

Release files for fourtheorem-tempo-worker 0.6.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 fourtheorem-tempo-worker 0.6.0
File Size Uploaded Provenance
fourtheorem_tempo_worker-0.6.0.tar.gz 10.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for fourtheorem-tempo-worker 0.6.0
File Interpreter ABI Platform
fourtheorem_tempo_worker-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.6 kB

Release files / fourtheorem_tempo_worker-0.6.0.tar.gz

Download URL fourtheorem_tempo_worker-0.6.0.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
acbad99cfbe9594ff207f68e7f8062f2c14f30515ce163744f160660b408d4fa
BLAKE2b-256 checksum
How to use checksums
1f943bcd0def93c18581007e296b014870384a6875fd91bd4ad376aa17b59b2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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 / fourtheorem_tempo_worker-0.6.0-py3-none-any.whl

Download URL fourtheorem_tempo_worker-0.6.0-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e50a4e704966c669c720400e52046f0d5960553614b619d0d101d08153ad2dee
BLAKE2b-256 checksum
How to use checksums
d56bbafcf4d031a290d8c29fdc0ae62ea4e9019435a4334d21a052d9ea1c3cba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","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 fourtheorem-tempo-worker 0.6.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.

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