> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Implement a Python worker

Run the handler with the `bijection-compute` Python package on your own
compute. The handler receives the arguments admitted by the
[external job](https://docs.bijection.com/transforms/external-runtimes.md) and returns a value matching
the job's `returns` type.

```python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import os

from bijection_compute.worker import worker_function

def forecast(args, run):
    run.progress({"step": "summing"})
    return {"total": sum(args["values"])}

CATALOG = {
    "forecast": worker_function(
        forecast,
        contract_digest=os.environ["FORECAST_CONTRACT_DIGEST"],
    ),
}
```

Use the codecs `digest` of the resolved `bijection.interface/v1` function
entry (`{args, returns, defaults?}`, as `bijection.worker.contract_digest`
and `bijection workers` compute it) when publishing the worker. On the application side,
`contractDigest(forecast)` from `@bijectionhq/pack-compute` returns the
digest of the declared job. Keep the worker artifact's digest pinned to its
own contract so that a stale worker is refused.

Your launcher starts `python -m bijection_compute.worker module:CATALOG`
with the run context in `BIJECTION_CONTEXT`. Keep that context private.
It contains the credential the worker uses to post progress and answer
the original task.

A single-function job can call `serve_run(forecast)` instead. For dataset
work, the [pipeline](https://docs.bijection.com/transforms/pipelines.md) gives the worker its pinned input
versions and leases; use your own libraries to compute over them. Datasets
admits the output under the app's publication policy.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.