PipelineContext: Runtime Context for Tasks
PipelineContext is a typed dataclass that the pipeline framework automatically builds and injects into any task that declares a ctx parameter. It carries the user, dataset, and per-item context for the current pipeline run, and provides an extras dict for custom state.
Fields
| Field | Type | Description |
|---|---|---|
user | Any | The user that triggered the pipeline. Used for access control and provenance. |
dataset | Any | The resolved dataset object for the current run. |
data_item | Any | The individual data item being processed in this pipeline execution. |
pipeline_name | Optional[str] | The name passed to run_pipeline or run_tasks. |
extras | Dict[str, Any] | Arbitrary key/value state you can pass into the pipeline and read in any task. Defaults to {}. |
How injection works
The framework inspects every task function’s signature at construction time. If it finds a parameter namedctx, it passes the current PipelineContext as that argument when the task runs. Matching is by parameter name, not by type annotation.
ctx simply receive no context and are unaffected.
Using extras for custom pipeline state
Pass a dict as the context argument to run_pipeline (or extras to run_tasks). Every task in the pipeline can read those values from ctx.extras.
ctx.extras is always a plain dict — it is never None.
Examples and details
Accessing user and dataset in a task
Accessing user and dataset in a task
The The built-in
user and dataset fields are most useful when you need to write provenance records or apply per-tenant logic:add_data_points task already does this automatically, so you typically only need to read these fields when writing your own storage tasks.Extras persist across chained tasks
Extras persist across chained tasks
All tasks in the same pipeline run share the same
PipelineContext object, so values written during construction remain available in every downstream task:Making ctx optional
Making ctx optional
Always default
ctx to None so the task can also be called directly in tests or scripts without a running pipeline:Tasks
Learn how tasks are defined and composed
Pipelines
See how tasks and context flow through pipeline runs
Custom Tasks & Pipelines
Step-by-step guide to building your own pipeline