Filtering API Reference¶
GtfsFilter¶
GtfsFilter ¶
Provides filtering and querying capabilities for GTFS feeds.
This class wraps a GtfsFeed or LazyGtfsFeed and provides convenient methods for filtering data by various criteria.
Attributes:
| Name | Type | Description |
|---|---|---|
feed |
GtfsFeed | LazyGtfsFeed
|
The underlying GTFS feed to filter. |
__init__ ¶
Initialize the filter with a GTFS feed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed
|
GtfsFeed | LazyGtfsFeed
|
A GtfsFeed or LazyGtfsFeed instance to filter. |
required |
get_stop ¶
Get a stop by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_id
|
str
|
The stop ID to look up. |
required |
Returns:
| Type | Description |
|---|---|
Stop | None
|
The Stop object, or None if not found. |
get_route ¶
Get a route by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_id
|
str
|
The route ID to look up. |
required |
Returns:
| Type | Description |
|---|---|
Route | None
|
The Route object, or None if not found. |
get_trip ¶
Get a trip by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trip_id
|
str
|
The trip ID to look up. |
required |
Returns:
| Type | Description |
|---|---|
Trip | None
|
The Trip object, or None if not found. |
get_agency ¶
Get an agency by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agency_id
|
str
|
The agency ID to look up. |
required |
Returns:
| Type | Description |
|---|---|
Agency | None
|
The Agency object, or None if not found. |
get_calendar ¶
Get a calendar entry by service ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_id
|
str
|
The service ID to look up. |
required |
Returns:
| Type | Description |
|---|---|
Calendar | None
|
The Calendar object, or None if not found. |
trips_for_route ¶
Get all trips for a specific route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_id
|
str
|
The route ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Trip]
|
List of Trip objects for the specified route. |
stop_times_for_route ¶
Get all stop times for a specific route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_id
|
str
|
The route ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[StopTime]
|
List of StopTime objects for trips on the specified route. |
stops_for_route ¶
Get all unique stops served by a specific route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_id
|
str
|
The route ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Stop]
|
List of unique Stop objects served by the route. |
routes_for_agency ¶
Get all routes operated by a specific agency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agency_id
|
str
|
The agency ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Route]
|
List of Route objects for the specified agency. |
trips_for_agency ¶
Get all trips for routes operated by a specific agency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agency_id
|
str
|
The agency ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Trip]
|
List of Trip objects for routes operated by the agency. |
stop_times_for_trip ¶
Get all stop times for a specific trip, ordered by sequence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trip_id
|
str
|
The trip ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[StopTime]
|
List of StopTime objects for the trip, sorted by stop_sequence. |
stops_for_trip ¶
Get all stops for a specific trip, in sequence order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trip_id
|
str
|
The trip ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Stop]
|
List of Stop objects for the trip, in stop sequence order. |
stop_times_at_stop ¶
Get all stop times at a specific stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_id
|
str
|
The stop ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[StopTime]
|
List of StopTime objects at the specified stop. |
trips_serving_stop ¶
Get all trips that serve a specific stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_id
|
str
|
The stop ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Trip]
|
List of Trip objects that stop at the specified stop. |
routes_serving_stop ¶
Get all routes that serve a specific stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_id
|
str
|
The stop ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Route]
|
List of Route objects that serve the specified stop. |
trips_for_service ¶
Get all trips for a specific service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
service_id
|
str
|
The service ID to filter by. |
required |
Returns:
| Type | Description |
|---|---|
list[Trip]
|
List of Trip objects using the specified service. |
active_services_on ¶
Get all services active on a specific date.
Takes into account both the regular calendar and calendar_dates exceptions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_input
|
str | date
|
The date to check (string "YYYY-MM-DD" or date object). |
required |
Returns:
| Type | Description |
|---|---|
list[Calendar]
|
List of Calendar objects for services active on the date. |
trips_on_date ¶
Get all trips running on a specific date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
date_input
|
str | date
|
The date to check (string "YYYY-MM-DD" or date object). |
required |
Returns:
| Type | Description |
|---|---|
list[Trip]
|
List of Trip objects running on the specified date. |
shape_for_trip ¶
Get the shape for a specific trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trip_id
|
str
|
The trip ID to get the shape for. |
required |
Returns:
| Type | Description |
|---|---|
Shape | None
|
The Shape object for the trip, or None if no shape assigned. |
route_stop_count ¶
Get the number of unique stops served by a route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_id
|
str
|
The route ID to count stops for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of unique stops on the route. |
route_trip_count ¶
Get the number of trips for a route.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
route_id
|
str
|
The route ID to count trips for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of trips on the route. |
stop_trip_count ¶
Get the number of trips serving a stop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_id
|
str
|
The stop ID to count trips for. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of trips serving the stop. |
Constructor¶
Create a filter for the given GTFS feed.
Lookup Methods¶
get_stop¶
Get a stop by its ID.get_route¶
Get a route by its ID.get_trip¶
Get a trip by its ID.get_agency¶
Get an agency by its ID.get_calendar¶
Get a calendar entry by service ID.Route Filtering¶
trips_for_route¶
Get all trips for a specific route.stop_times_for_route¶
Get all stop times for trips on a route.stops_for_route¶
Get all unique stops served by a route.Trip Filtering¶
stop_times_for_trip¶
Get all stop times for a trip, sorted by stop_sequence.stops_for_trip¶
Get all stops for a trip, in sequence order.Stop Filtering¶
stop_times_at_stop¶
Get all stop times at a specific stop.trips_serving_stop¶
Get all trips that serve a stop.routes_serving_stop¶
Get all routes that serve a stop.Agency Filtering¶
routes_for_agency¶
Get all routes operated by an agency.trips_for_agency¶
Get all trips for routes operated by an agency.Service/Date Filtering¶
trips_for_service¶
Get all trips for a specific service.active_services_on¶
Get all services active on a specific date.Takes into account both calendar (day-of-week patterns) and calendar_dates (exceptions).
Parameters:
- date_input: Date as string ("YYYY-MM-DD" or "YYYYMMDD") or datetime.date object
Raises:
- InvalidDateError: If the date string cannot be parsed