Skip to content

Pipeline context

Rendered at build time from the docstrings and signatures of continuous_gtfs.context. A member with no description has no docstring yet; the fix is in the code, never on this page.

PipelineContext: the inputs, output, id mappings, findings, and clock a step works against.

PipelineContext — shared state passed to each step.

logger module-attribute

logger = logging.getLogger(__name__)

FINDING_SEVERITIES module-attribute

FINDING_SEVERITIES = ('error', 'warning', 'info')

DEFAULT_FINDING_SEVERITY module-attribute

DEFAULT_FINDING_SEVERITY = 'warning'

PipelineContext dataclass

PipelineContext(
    inputs: Mapping[str, Any] = dict(),
    output: dict[str, Any] = dict(),
    environment: str = "development",
    config: dict[str, Any] = dict(),
    metadata: dict[str, Any] = dict(),
    id_mappings: dict[str, dict[str, str | None]] = dict(),
    findings: list[dict[str, Any]] = list(),
    now: datetime = system_now(),
)

Context passed to each step's apply() method.

Attributes:

Name Type Description
inputs Mapping[str, Any]

Named inputs populated by the framework before the first step runs. The shape of each value depends on the source asset's content_kind (see specs/asset-registry.md §Content Kinds): gtfs_schedule_zip → dict[str, polars.DataFrame] csv_table → polars.DataFrame gtfs_rt_protobuf → gtfs_realtime_pb2.FeedMessage opaque_bytes → bytes file_tree → FileTree (read-only Traversable root; see continuous_gtfs.file_tree) Transforms read ctx.inputs[name] by the name declared in the pipeline's INPUTS manifest.

The dict itself is read-only (wrapped in types.MappingProxyType) — transforms can't add, remove, or replace entries; attempts raise TypeError. Inner dicts (the dict[filename → DataFrame] for a gtfs_schedule_zip input) are also wrapped, so ctx.inputs["schedule"]["stops.txt"] = ... raises too. Polars DataFrame values are NOT deep-frozen: a transform that calls a polars in-place method (drop_in_place, etc.) on a value could still mutate the underlying DataFrame. Polars' API is mostly functional/copy-on-assignment, so idiomatic usage is self-enforcing — the runtime guarantee stops at the dict layer.

output dict[str, Any]

Mutable working set that transforms populate. The final state of ctx.output is what the worker serializes back as the run's artifact(s). Schedule pipelines seed it from an input (e.g. ctx.output = dict(ctx.inputs["schedule"])). RT pipelines populate it keyed by canonical feed name (vehicle_positions, trip_updates, service_alerts).

environment str

Current environment name (production, staging, etc.)

config dict[str, Any]

Arbitrary pipeline configuration.

metadata dict[str, Any]

Mutable dict for steps to share non-data state.

id_mappings dict[str, dict[str, str | None]]

Cross-file ID mapping for cascade operations (schedule only). Key: "{file}.{field}" (e.g. "routes.txt.route_id"); value: {old_id: new_id} or {removed_id: None}.

findings list[dict[str, Any]]

Every finding emitted during the run, in emission order — the cumulative record local runs and tests read. The executor additionally drains a per-step buffer into each StepResult.findings, which is what the worker transports. See specs/transform-framework.md §Findings.

now datetime

The evaluation moment, tz-aware UTC — the clock every step that reasons about time reads instead of the system clock. The worker sets it from the dispatch's evaluated_at (receipt time when absent), the CLI from --now (invocation time when absent); constructed bare, it defaults to construction time. A naive datetime is rejected. See specs/transform-framework.md §PipelineContext.

inputs class-attribute instance-attribute

inputs: Mapping[str, Any] = field(default_factory=dict)

output class-attribute instance-attribute

output: dict[str, Any] = field(default_factory=dict)

environment class-attribute instance-attribute

environment: str = 'development'

config class-attribute instance-attribute

config: dict[str, Any] = field(default_factory=dict)

metadata class-attribute instance-attribute

metadata: dict[str, Any] = field(default_factory=dict)

id_mappings class-attribute instance-attribute

id_mappings: dict[str, dict[str, str | None]] = field(
    default_factory=dict
)

findings class-attribute instance-attribute

findings: list[dict[str, Any]] = field(default_factory=list)

now class-attribute instance-attribute

now: datetime = field(default_factory=system_now)

emit_finding

emit_finding(
    code: str,
    *,
    severity: str = DEFAULT_FINDING_SEVERITY,
    message: str = "",
    context: Mapping[str, Any] | None = None,
    occurrence_count: int = 1,
) -> None

Report a structured problem this step observed.

Performs no I/O, mutates no data, and cannot fail the run: every malformed argument is normalized and recorded on the finding's emit_errors rather than raised, and any unexpected internal error is swallowed with a log line. Emitting the same code with the same subject values twice is two occurrences of one finding, not two findings — the platform counts them per run (specs/issues.md §Finding counts).

The emitter passes a flat context map and does NOT split grouping keys from detail: the platform selects the code's declared subject keys out of context and treats the rest as non-grouping detail, so one place decides grouping.

Parameters:

Name Type Description Default
code str

The finding code, matching a declared entry on the step. An undeclared code is still ingested (at class grain) and additionally reported — declaring is discoverability, not enforcement.

required
severity str

"error" | "warning" | "info"; anything else is coerced to "warning" and recorded.

DEFAULT_FINDING_SEVERITY
message str

Human line. Free to interpolate run-specific values — the message never participates in grouping.

''
context Mapping[str, Any] | None

Flat context map. Non-string values are stringified.

None
occurrence_count int

Occurrences this single call stands for (default 1), for emitters that already know their own total.

1

add_id_mapping

add_id_mapping(
    file: str,
    field_name: str,
    old_id: str,
    new_id: str | None,
) -> None

Record an ID rename or removal for cross-file cascade.

Parameters:

Name Type Description Default
file str

GTFS filename (e.g. "routes.txt")

required
field_name str

Field name (e.g. "route_id")

required
old_id str

The original ID value

required
new_id str | None

The new ID value, or None if removed

required

get_id_mappings

get_id_mappings(
    file: str, field_name: str
) -> dict[str, str | None]

Get all ID mappings for a given file and field.

Returns empty dict if no mappings exist.