Scanning and running¶
Rendered at build time from the docstrings and signatures of continuous_gtfs.scanner and continuous_gtfs.pipelines. A member with no description has no docstring yet; the fix is in the code, never on this page.
How a pipeline folder becomes an ordered list of steps (scan_pipeline, resolve_dag), and the runners that execute it in a test or a script without the CLI.
Scanning a pipeline folder¶
Pipeline folder scanner and DAG resolver.
INPUT_ROLES
module-attribute
¶
INPUT_ROLES: tuple[InputRole, ...] = (
"primary",
"supplemental",
"baseline",
)
InputSpec
¶
Bases: TypedDict
One normalized INPUTS manifest entry.
load_inputs_manifest reduces both manifest forms — a bare
content_kind string (required) and a {"content_kind": ...,
"optional": ..., "role": ...} mapping — to this shape so every
consumer (worker dispatch validation, registration, the local CLI)
reads one structure. role is None when the entry declares none
(a reference input). See specs/transform-framework.md §INPUTS manifest.
scan_pipeline
¶
scan_pipeline(
folder: str | Path, root: str | Path | None = None
) -> list[Step]
Scan a folder for Step instances and return them with names inferred.
Imports all .py files in the folder (non-recursive), finds module-level objects that are isinstance(obj, Step), and infers the step name from the variable name.
The folder is treated as a Python package so files can use relative
imports (e.g., from .feed_info import update_feed).
Every step leaves with its definition provenance stamped
(specs/transform-framework.md §Step Snapshot at Registration):
source_file relative to root — the pipeline codebase root, which
defaults to the parent of a pipelines/ folder or else the folder's
parent — source_hash (set here from definition_params() for a
builtin instance; already set by @step for a function) and
module_hash over the defining module's bytes — each with the text it
hashes beside it (source, module_source), set exactly when the hash
is.
likely_checks
¶
likely_checks(steps: list[Step]) -> list[str]
Names of @step functions that declare findings and operate on no
files — usually checks declared as transforms. The local CLI warns about
them (specs/transform-framework.md §Checks); worker startup and
registration stay quiet.
validate_roles
¶
validate_roles(steps: list[Step]) -> None
Reject DAG edges that involve a check (specs/transform-framework.md §Checks): a check runs after every transform and no step orders against it. A check's own before/after is already rejected where it is declared (the @check decorator / Check constructor); this catches a transform that names a check in its before/after.
load_feed_type
¶
load_feed_type(folder: str | Path) -> str
Load the FEED_TYPE constant from a pipeline folder's init.py.
Every pipeline declares FEED_TYPE alongside INPUTS so the framework can route dispatches to the right execution path (DataFrame mutation vs FeedMessage transform) and the worker can advertise per-pipeline capabilities at registration time. See specs/transform-framework.md §INPUTS manifest.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if the folder has no init.py. |
ValueError
|
if FEED_TYPE is missing or not one of the valid kinds. |
discover_pipelines
¶
discover_pipelines(repo_root: str | Path) -> list[Path]
Find every pipeline directory under
A pipeline is any immediate subdirectory of
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if |
load_inputs_manifest
¶
load_inputs_manifest(
folder: str | Path,
) -> dict[str, InputSpec]
Load the INPUTS manifest from a pipeline folder's init.py.
Every pipeline must declare its named inputs as a module-level
INPUTS dict in the folder's __init__.py (see
specs/transform-framework.md §INPUTS manifest). Each value is either
a bare content_kind string — a required input — or a mapping
{"content_kind": <kind>, "optional": <bool>, "role": <role>}, where
optional: True makes the input optional and role names what
the input is to the output (primary, supplemental or baseline). Both forms
are normalized to InputSpec here so callers never see the raw
shape; manifest_kinds() gives the flat name → content_kind view the
parser registry wants.
The manifest is the pipeline's input contract — the worker validates dispatches against it and reports it at registration, and the CLI uses it to resolve content_kind for local --input flags.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
if the folder has no init.py. |
ValueError
|
if the manifest is missing, malformed, references
an unknown content_kind, or breaks a role rule (two |
manifest_kinds
¶
manifest_kinds(
manifest: Mapping[str, InputSpec],
) -> dict[str, str]
Flat name → content_kind view of a normalized INPUTS manifest.
The parser registry only cares about kinds; this is what
load_inputs and the worker's per-slot parse consume.
required_input_names
¶
required_input_names(
manifest: Mapping[str, InputSpec],
) -> list[str]
Names of the manifest's required (non-optional) inputs, in order.
dag_edges
¶
dag_edges(steps: list[Step]) -> list[tuple[Step, Step]]
The DAG's effective edge list: (a, b) means a must run before b.
Wildcard declarations expand here exactly as execution orders them —
an after="*" step gains an edge from every other step (except fellow
after-wildcards, which would cycle), symmetrically for before="*" —
so every renderer of the DAG (resolve_dag itself, the ReactFlow export,
the CLI's mermaid view) shows the edges that actually execute rather
than each re-deriving (or crashing on) the "*" sentinel (#683).
Checks carry no edges, and wildcards range over transforms only (specs/transform-framework.md §Checks in the resolved order): a check's position is its role — after every transform — not an edge.
resolve_dag
¶
resolve_dag(steps: list[Step]) -> list[Step]
Topological sort of steps using after/before references.
Returns steps in execution order. Raises ValueError on cycles. Within a dependency level, sorts by (priority, name) for determinism.
A step declared with before="*" is expanded into implicit edges to
every other step in the input — use it for init steps that must run
before any other step the scanner discovers (e.g. one that seeds
ctx.output from a specific input). after="*" is symmetric — the
step runs after every other step, useful for teardown / summary
transforms. Multiple wildcards of the same kind don't edge to each
other (that would be a cycle); they order among themselves via
(priority, name) in the ready queue.
Checks (specs/transform-framework.md §Checks in the resolved order)
follow every transform, ordered by name; they carry no edges, and
priority does not apply to them.
select_with_ancestors
¶
select_with_ancestors(
steps: list[Step], target_name: str
) -> list[Step]
Return the target step plus all its transitive dependencies, in DAG order.
Ancestors are computed from:
afterreferences (direct) — Y has X in itsafterlist means Y depends on X.- Reverse
beforereferences — Y has X in itsbeforelist means Y runs before X, i.e. X depends on Y. before="*"wildcards — any step declared withbefore="*"implicitly runs before every other step in the DAG, so it's an ancestor of every selected step (including selectedafter="*"steps). Without this,--selecton a pipeline with a wildcard init step (seedingctx.output, for example) would run the target against an un-seeded context.
A check target selects every transform: a check reads the output every transform produced (specs/transform-framework.md §Checks in the resolved order). A transform target never selects a check.
after="*" is deliberately NOT pulled in as a descendant —
select_with_ancestors walks the UP direction only (things the
target needs). Teardown steps run after everything else; they're
downstream of the target, not prerequisites for it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
steps
|
list[Step]
|
The full resolved DAG (output of resolve_dag). |
required |
target_name
|
str
|
Name of the step to select. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if target_name matches no step. |
export_reactflow
¶
export_reactflow(steps: list[Step]) -> dict
Export the resolved DAG as ReactFlow-compatible JSON.
Running a pipeline¶
Pipeline runners for schedule and realtime feeds.
run_realtime_pipeline
¶
run_realtime_pipeline(
inputs: dict[str, Any],
steps: list[Step],
*,
environment: str = "production",
executor: PipelineExecutor | None = None,
disabled_steps: list[str] | None = None,
now: datetime | None = None,
) -> RealtimePipelineResult
Run the RT pipeline against already-parsed inputs.
Each input declared in the pipeline's INPUTS manifest as
gtfs_rt_protobuf arrives as a parsed FeedMessage. ctx.output
starts empty; the pipeline is expected to seed it in an init step
(typically @step(before="*")), picking which inputs become
outputs and under what names — e.g. canonical GTFS-RT names like
vehicle_positions / trip_updates, or a multi-vendor merge into
one output. The framework does not auto-mirror: silently emitting
outputs keyed by whatever the agency named its inputs produces
confusing artifact URLs and hides pipeline intent.
Each output FeedMessage in ctx.output is encoded to both PB and
JSON at the end — there is no combined feed. See
realtime-pipeline.md §Per-Feed Outputs.
extract_zip
¶
extract_zip(zip_bytes: bytes) -> dict[str, pl.DataFrame]
Extract GTFS zip to dict of filename -> DataFrame (all string columns).
package_zip
¶
package_zip(
datasets: dict[str, DataFrame], *, compress: bool = True
) -> bytes
Package datasets back into a GTFS zip, byte-deterministically.
Identical tables always yield identical bytes (specs/asset-registry.md §Output Assets): the canonical packer fixes entry order, timestamps, attributes, and the compression level, so re-evaluating an unchanged checkpoint repeats the latest output version instead of minting one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datasets
|
dict[str, DataFrame]
|
filename -> DataFrame map. |
required |
compress
|
bool
|
If True (default) use DEFLATE at the packer's pinned level. If False, use STORE (no compression) — faster, used for --quick dev runs when the zip is only produced for inspection, not for distribution. |
True
|
run_schedule_pipeline
¶
run_schedule_pipeline(
inputs: dict[str, Any],
steps: list[Step],
*,
environment: str = "production",
executor: PipelineExecutor | None = None,
quick: bool = False,
disabled_steps: list[str] | None = None,
now: datetime | None = None,
) -> SchedulePipelineResult
Run the full schedule pipeline against already-parsed inputs.
inputs is the already-parsed map of named inputs the pipeline
declares in its INPUTS manifest — worker (production) and CLI (local)
both run inputs through the parser registry before handing them off.
ctx.output starts empty. The pipeline is expected to seed it in an
init step — typically one using before="*" to guarantee ordering —
that picks the right input(s) to seed from. The framework does not
auto-seed from a convention-based guess: with multiple
gtfs_schedule_zip inputs the right choice isn't unambiguous, and
picking silently would produce wrong outputs rather than a clear
failure. If ctx.output is still empty after the DAG runs,
validate_output and package surface it as an explicit "missing
required file" failure instead of a silent success with empty
artifacts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
dict[str, Any]
|
Named inputs, values already parsed per each asset's content_kind. gtfs_schedule_zip inputs are dict[str, DataFrame]; csv_table inputs are polars DataFrame; etc. |
required |
steps
|
list[Step]
|
DAG-resolved steps to execute. |
required |
environment
|
str
|
Pipeline environment name. |
'production'
|
executor
|
PipelineExecutor | None
|
Optional pre-configured executor (for hooks). Defaults to continue mode. |
None
|
quick
|
bool
|
Dev-loop mode. Skips validate_output and the output-zip packaging step. Caller produces a zip or diffs from result.output directly as needed. |
False
|
validate_gtfs
¶
validate_gtfs(
datasets: dict[str, DataFrame],
) -> dict[str, list[str]]
Basic GTFS structural validation.