TransitLand¶
TransitLandDownloader ¶
Bases: BaseGTFSDownloader
Client for searching and downloading feeds from Transitland.
See https://www.transit.land/documentation/rest-api for the full API reference. Requires a Transitland API key.
Initialize the client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
Transitland API key. If not provided, it is read
from the |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no API key is available. |
Source code in pyGTFSHandler/downloaders/transitland.py
search_feeds ¶
search_feeds(aoi: Optional[AOIType] = None, lat: Optional[float] = None, lon: Optional[float] = None, radius: Optional[float] = None, country_code: Optional[str] = None, state: Optional[str] = None, city: Optional[str] = None, search: Optional[str] = None, operator_onestop_id: Optional[str] = None, limit: Optional[int] = 1000, spec: str = 'gtfs') -> List[GTFSFeedMetadata]
Search Transitland's catalog for feeds matching filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Optional[AOIType]
|
Polygon, MultiPolygon, GeoDataFrame, or GeoSeries defining
a geographic area; converted to a bounding box ( |
None
|
lat
|
Optional[float]
|
Latitude for a point-radius search. Requires |
None
|
lon
|
Optional[float]
|
Longitude for a point-radius search. Requires |
None
|
radius
|
Optional[float]
|
Search radius in meters around |
None
|
country_code
|
Optional[str]
|
ISO 3166-1 alpha-2 country code to filter by
(Transitland's |
None
|
state
|
Optional[str]
|
State/province/subdivision name to filter by
(Transitland's |
None
|
city
|
Optional[str]
|
City name to filter by (Transitland's |
None
|
search
|
Optional[str]
|
Free-text search over feed and operator names. |
None
|
operator_onestop_id
|
Optional[str]
|
Restrict to feeds of a specific operator, identified by its Transitland onestop id. |
None
|
limit
|
Optional[int]
|
Maximum number of feeds to return. Results are fetched
page by page (up to |
1000
|
spec
|
str
|
GTFS specification to filter by. Defaults to |
'gtfs'
|
Returns:
| Type | Description |
|---|---|
List[GTFSFeedMetadata]
|
A list of |
List[GTFSFeedMetadata]
|
usable static GTFS download URL. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If only one of |
Source code in pyGTFSHandler/downloaders/transitland.py
find_feed_version_history ¶
List every published static GTFS version recorded for a feed.
Uses GET /feeds/{feed_key}/feed_versions, which returns
Transitland's full archive of past fetches for the feed, each
tagged with earliest_calendar_date/latest_calendar_date -- the
real service period Transitland computed from that version's own
calendar.txt/calendar_dates.txt, not just when it was fetched
(fetched_at).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed_key
|
str
|
Feed lookup key: an integer id or onestop id. |
required |
limit
|
int
|
Maximum number of feed versions to fetch. |
1000
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Raw feed_version dictionaries, sorted oldest to newest by |
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
last, in API order). |
Source code in pyGTFSHandler/downloaders/transitland.py
download_historic_stack ¶
download_historic_stack(output_path: str, feed_key: str, start_date: DateLike, end_date: DateLike, day_separation: int = 1, overwrite: bool = False, aoi: Optional[AOIType] = None) -> Optional[str]
Download and stitch a feed's version history into one GTFS zip.
Mirrors NAPDownloader.download_historic_stack/
MobilityDatabaseDownloader.download_historic_stack, using
find_feed_version_history's earliest_calendar_date as the
trim anchor -- already a real, Transitland-computed service start
date, unlike NAP's raw publication timestamp.
Note: downloading any feed_version other than the single most
recent one requires a paid (or free Hobbyist/Academic) Transitland
plan; see _download_feed_version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str
|
Directory to assemble the stitched feed in. |
required |
feed_key
|
str
|
Feed lookup key: an integer id or onestop id. |
required |
start_date
|
DateLike
|
Start of the date range to cover. Accepts
|
required |
end_date
|
DateLike
|
End of the date range to cover. |
required |
day_separation
|
int
|
Minimum number of days a version is assumed to stay valid for, if service periods don't force it shorter. |
1
|
overwrite
|
bool
|
If True, redo the feed even if its stitched output zip already exists. |
False
|
aoi
|
Optional[AOIType]
|
Optional AOI passed through to |
None
|
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Path to the written |
Optional[str]
|
or |
Optional[str]
|
requested range. |
Source code in pyGTFSHandler/downloaders/transitland.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 | |