Mobility Database¶
MobilityDatabaseDownloader ¶
Bases: BaseGTFSDownloader
Client for searching and downloading feeds from the Mobility Database.
Authenticates via OAuth2 using a long-lived refresh token (obtained from the Mobility Database website), which is exchanged for short-lived access tokens as needed.
Initialize the client and obtain an initial access token.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
Optional[str]
|
Long-lived refresh token obtained from the Mobility
Database website. If not provided, it is read from the
|
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no refresh token is available. |
Source code in pyGTFSHandler/downloaders/mobility_database.py
search_feeds ¶
search_feeds(aoi: Optional[AOIType] = None, limit: Optional[int] = 100000, offset: Optional[int] = None, provider: Optional[Union[str, List[Optional[str]]]] = None, producer_url: Optional[Union[str, List[Optional[str]]]] = None, country_code: Optional[Union[str, List[Optional[str]]]] = None, subdivision_name: Optional[Union[str, List[Optional[str]]]] = None, municipality: Optional[Union[str, List[Optional[str]]]] = None, bounding_filter_method: str = 'partially_enclosed', is_official: Optional[bool] = None) -> List[GTFSFeedMetadata]
Search the Mobility Database for GTFS feeds matching filters.
Supports multiple values per filter (client-side merged across
combinations) and automatic pagination for limit values above
the API's per-request page size (200).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aoi
|
Optional[AOIType]
|
Polygon, MultiPolygon, GeoDataFrame, or GeoSeries defining a geographic area to filter by. |
None
|
limit
|
Optional[int]
|
Maximum number of feeds to return. Values above 200 trigger automatic multi-page fetching. |
100000
|
offset
|
Optional[int]
|
Offset for pagination. |
None
|
provider
|
Optional[Union[str, List[Optional[str]]]]
|
Provider name filter. Accepts a string, a list of
strings, or a list including |
None
|
producer_url
|
Optional[Union[str, List[Optional[str]]]]
|
Producer URL filter, same semantics as |
None
|
country_code
|
Optional[Union[str, List[Optional[str]]]]
|
Country code filter, same semantics as |
None
|
subdivision_name
|
Optional[Union[str, List[Optional[str]]]]
|
Subdivision name filter, same semantics as
|
None
|
municipality
|
Optional[Union[str, List[Optional[str]]]]
|
Municipality filter, same semantics as |
None
|
bounding_filter_method
|
str
|
Spatial inclusion rule when |
'partially_enclosed'
|
is_official
|
Optional[bool]
|
If set, filter by whether the feed is official. |
None
|
Returns:
| Type | Description |
|---|---|
List[GTFSFeedMetadata]
|
A list of |
List[GTFSFeedMetadata]
|
usable download URL. |
Source code in pyGTFSHandler/downloaders/mobility_database.py
312 313 314 315 316 317 318 319 320 321 322 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 | |
find_dataset_history ¶
List every published dataset (version) recorded for a feed.
Uses /v1/gtfs_feeds/{id}/datasets, which -- unlike
search_feeds's latest_dataset -- returns the full publication
history MobilityData has recorded for the feed, each already
tagged with service_date_range_start/service_date_range_end:
the real service period MobilityData computed from that dataset's
own calendar.txt/calendar_dates.txt, not just when it was
downloaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
feed_id
|
str
|
Mobility Database feed id (e.g. |
required |
limit
|
int
|
Maximum number of dataset versions to fetch. |
1000
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
Raw dataset dictionaries, sorted oldest to newest by |
List[Dict[str, Any]]
|
|
List[Dict[str, Any]]
|
last, in API order). |
Source code in pyGTFSHandler/downloaders/mobility_database.py
download_historic_stack ¶
download_historic_stack(output_path: str, feed_id: 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 dataset history into one GTFS zip.
Mirrors NAPDownloader.download_historic_stack, but since
find_dataset_history already reports each version's real
service date range (computed by MobilityData from that version's
own calendar), no extra validation of the anchor date is needed
before trimming (contrast with NAP's raw publication timestamp,
handled by downloaders.spain.utils.resolve_publication_start_date).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
str
|
Directory to assemble the stitched feed in. |
required |
feed_id
|
str
|
Mobility Database feed id (e.g. |
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/mobility_database.py
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 | |