Realtime builtins¶
Rendered at build time from the continuous_gtfs.builtins.realtime package: its categories, each builtin's docstring, signature and declared findings. To change this page, change the code; the site is never edited by hand.
Parameterized steps for GTFS-RT feeds, operating in place on the protobuf FeedMessage objects in ctx.output, one per feed type. How outputs are keyed and how entity types are handled is in the builtins guide.
| Builtin | Category | What it does |
|---|---|---|
FilterStopsByID |
Filtering | Drop references to blocklisted stops from trip updates and vehicle positions. |
CombineFeeds |
Merging | Merge entities from additional realtime inputs into one output feed. |
RenameVehicles |
Identifiers | Prefix vehicle ids and labels with a string. |
TransformTripId |
Identifiers | Rewrite trip ids on trip updates and vehicle positions with a regex substitution. |
ExpireCancelledTrips |
Schedule-aware | Drop cancellations whose trip has already ended per the schedule. |
InsertMissingCancellations |
Schedule-aware | Cancel scheduled trips that should be running but are absent from the feed. |
ConvertScheduledToNew |
Schedule-aware | Rewrite SCHEDULED trips as ADDED with fresh trip ids. |
UpdateFeedHeader |
Feed header | Set the GTFS-RT version on every output feed's header. |
PassThrough |
Testing | Do nothing; a baseline for equivalence tests and measurement. |
Filtering¶
FilterStopsByID
¶
FilterStopsByID(
blocked_stop_ids: set[str] | None = None,
*,
blocked_stop_id_regex: str | None = None,
**kwargs: Any,
)
Drop references to blocklisted stops from trip updates and vehicle positions.
On a TripUpdate, the stop_time_update entries whose stop_id is
blocked are removed. On a VehiclePosition at a blocked stop,
stop_id, current_stop_sequence and current_status are cleared.
Alerts are left alone. Use it to hide stations that are not yet open
during simulated service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blocked_stop_ids
|
set[str] | None
|
Stop ids to block, matched exactly. |
None
|
blocked_stop_id_regex
|
str | None
|
A pattern a stop id must contain a match
for to be blocked (Python |
None
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
filter_stops = FilterStopsByID(blocked_stop_ids={"S108", "S109"})
filter_expansion = FilterStopsByID(blocked_stop_id_regex=r"^EXT_")
Merging¶
CombineFeeds
¶
CombineFeeds(
*, target: str, sources: list[str], **kwargs: Any
)
Merge entities from additional realtime inputs into one output feed.
Entities are added by id; an id already present in the target wins, so the primary feed takes precedence over the sources. Merging is within one feed type (two vehicle-positions sources into one vehicle-positions output); realtime outputs are per feed type, so there is no combined feed to merge across types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
The output feed to merge into (a |
required |
sources
|
list[str]
|
Input names ( |
required |
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
combine = CombineFeeds(
target="vehicle_positions",
sources=["vendor_b_positions", "vendor_c_positions"],
)
Identifiers¶
RenameVehicles
¶
RenameVehicles(id_prefix: str, **kwargs: Any)
Prefix vehicle ids and labels with a string.
Applies to entities with a vehicle.vehicle descriptor. Idempotent: an
id or label that already starts with the prefix is left alone. Use it
to namespace vehicles when combining feeds from several vendors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_prefix
|
str
|
The prefix to add, such as |
required |
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
rename = RenameVehicles(id_prefix="AGENCY-")
TransformTripId
¶
TransformTripId(
pattern: str, replacement: str, **kwargs: Any
)
Rewrite trip ids on trip updates and vehicle positions with a regex substitution.
Applies to trip_update.trip.trip_id and vehicle.trip.trip_id on
every output feed. Alert informed entities are not rewritten. Mirrors
the schedule
TransformTripId
so an agency can rewrite trip ids consistently across both outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
The regex to find (Python |
required |
replacement
|
str
|
The replacement text; capture groups are |
required |
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
transform_trip = TransformTripId(
pattern=r"^LONG_PREFIX_(\d+)$",
replacement=r"T-\1",
)
Schedule-aware¶
ExpireCancelledTrips
¶
ExpireCancelledTrips(
*,
target: str = "trip_updates",
schedule_input: str = "schedule",
previous_output_input: str | None = None,
service_day_threshold_hour: int = 4,
now: datetime | None = None,
**kwargs: Any,
)
Drop cancellations whose trip has already ended per the schedule.
A CANCELED entity in the target feed is kept only while its trip's
scheduled end has not passed; stale cancellations are dropped. Time is
resolved in the agency's local timezone from agency.txt. This is the
stateless half of the "preserve cancelled trips" contract; see
previous_output_input for the rest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
The feed to operate on. Cancellations are a trip-updates concept, so other feeds are never touched. |
'trip_updates'
|
schedule_input
|
str
|
The |
'schedule'
|
previous_output_input
|
str | None
|
Name of an input bound to this pipeline's
own previous output. When set, |
None
|
service_day_threshold_hour
|
int
|
Local hour at which the service day rolls over; trips before it belong to the previous day. |
4
|
now
|
datetime | None
|
The evaluation moment. Defaults to |
None
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
expire_cancellations = ExpireCancelledTrips()
# Carry in-progress cancellations across runs
expire_cancellations = ExpireCancelledTrips(
previous_output_input="previous_trip_updates",
)
InsertMissingCancellations
¶
InsertMissingCancellations(
*,
target: str = "trip_updates",
schedule_input: str = "schedule",
delay_seconds: int = 600,
service_day_threshold_hour: int = 4,
now: datetime | None = None,
**kwargs: Any,
)
Cancel scheduled trips that should be running but are absent from the feed.
For every trip whose service is active today per calendar.txt and
calendar_dates.txt: if its scheduled start passed at least
delay_seconds ago, its scheduled end is still ahead, and no entity in
the target feed references it (on trip_update.trip.trip_id or
vehicle.trip.trip_id), a CANCELED trip update is appended with
trip_id, route_id, start_date and schedule_relationship, under
entity id cancel_<trip_id>. Time is resolved in the agency's local
timezone from agency.txt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
The feed to operate on. |
'trip_updates'
|
schedule_input
|
str
|
The |
'schedule'
|
delay_seconds
|
int
|
How long after its scheduled start a missing trip is tolerated before it is cancelled. |
600
|
service_day_threshold_hour
|
int
|
Local hour at which the service day rolls over. |
4
|
now
|
datetime | None
|
The evaluation moment. Defaults to |
None
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
insert_cancellations = InsertMissingCancellations(delay_seconds=600)
ConvertScheduledToNew
¶
ConvertScheduledToNew(
*,
schedule_input: str = "schedule",
trip_id_prefix: str = "new_",
route_ids: set[str] | None = None,
**kwargs: Any,
)
Rewrite SCHEDULED trips as ADDED with fresh trip ids.
For every entity whose trip.schedule_relationship is SCHEDULED and
whose trip_id is in the schedule: the trip id is replaced with
<prefix><original>_<uuid8>, the relationship becomes ADDED, and
route_id and direction_id are filled from trips.txt when present.
Downstream consumers then treat the trip as added rather than as a
known scheduled trip, which is the point: it breaks the identity link
to a schedule the agency has not published yet. stop_time_update is
left as is; a pipeline that needs it filled from stop_times.txt
layers its own step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schedule_input
|
str
|
The |
'schedule'
|
trip_id_prefix
|
str
|
Prefix of the generated trip ids. |
'new_'
|
route_ids
|
set[str] | None
|
Convert only trips scheduled on these routes (per
|
None
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
unpublished_mode = ConvertScheduledToNew(route_ids={"R1"})
Feed header¶
UpdateFeedHeader
¶
UpdateFeedHeader(version: str = '2.0', **kwargs: Any)
Set the GTFS-RT version on every output feed's header.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
str
|
The |
'2.0'
|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
header = UpdateFeedHeader(version="2.0")
Testing¶
PassThrough
¶
PassThrough(
*,
after: list[Step] | Literal["*"] | None = None,
before: list[Step] | Literal["*"] | None = None,
priority: int = 100,
tags: list[str] | None = None,
data_owner: str | None = None,
enabled: bool = True,
findings: list[Any] | None = None,
**kwargs: Any,
)
Do nothing; a baseline for equivalence tests and measurement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
Any
|
Shared step parameters ( |
{}
|
Examples:
passthrough = PassThrough()