OneBusAway Python Client
The OneBusAway Python Client is a Python library for interacting with the OneBusAway API. It provides a simple and convenient way to access real-time transit data, schedules, and other information from various transit agencies.
Features
- Comprehensive API Coverage: Access a wide range of endpoints for retrieving transit data, including agency information, routes, stops, arrivals and departures, trip details, vehicle locations, and more.
- Flexible Usage: Use the library in both synchronous and asynchronous modes, making it suitable for various application types, including web applications, scripts, and data analysis tasks.
- Easy Integration: The library is designed to be intuitive and easy to use, with a straightforward API and comprehensive documentation.
- Robust Error Handling: Enjoy robust error handling with custom exceptions for common API errors, such as missing or invalid API keys, bad requests, and more.
- Well-Tested: The library is thoroughly tested, ensuring reliable and consistent behavior across different scenarios.
Installation
You can install the OneBusAway Python Client using pip:
pip install onebusaway
Getting Started
Follow these steps to get started with the OneBusAway Python Client:
-
Obtain an API Key: To use the OneBusAway API, you'll need to obtain an API key. Visit the OneBusAway Developers website to sign up and get your API key.
-
Set the API Key: Set the
OBA_API_KEYenvironment variable with your API key:
export OBA_API_KEY=your_api_key
- Import the Client: Import the
OneBusAwayclass from the library:
from onebusaway import OneBusAway
- Initialize the Client: Initialize the
OneBusAwayclient with the desired base URL (default isapi.pugetsound.onebusaway.org):
oba = OneBusAway(base_url="api.pugetsound.onebusaway.org")
- Use the Client: Now you can start using the client to interact with the OneBusAway API:
# Get a list of agencies with coverage
agencies = oba.agency_with_coverage()
# Get arrivals and departures for a stop
stop_id = "1_75403"
arrivals_and_departures = oba.arrivals_and_departures_for_stop(stop_id)
For more examples and detailed usage instructions, please refer to the Usage section.
Usage
The OneBusAway Python Client provides a wide range of methods to interact with the OneBusAway API. Here are some examples:
Agencies
# Get a list of agencies with coverage
agencies = oba.agency_with_coverage()
# Get details for a specific agency
agency_details = oba.agency("1", get_references=True)
Stops
# Get arrivals and departures for a stop
stop_id = "1_75403"
arrivals_and_departures = oba.arrivals_and_departures_for_stop(stop_id)
# Get schedule for a stop
stop_schedule = oba.schedule_for_stop(stop_id)
Routes
# Get routes for an agency
agency_id = "1"
routes = oba.routes_for_agency(agency_id)
# Get schedule for a route
route_id = "1_100"
route_schedule = oba.schedule_for_route(route_id)
Trips
# Get trips for a route
route_id = "1_100"
trips = oba.trips_for_route(route_id, includeSchedule=True)
# Get trip details
trip_id = "1_12345"
trip_details = oba.trip_details(trip_id, includeSchedule=True)
Vehicles
# Get vehicles for an agency
agency_id = "1"
vehicles = oba.vehicles_for_agency(agency_id)
For more details and a complete list of available methods, please refer to the API Reference section.
API Reference
The OneBusAway Python Client provides the following methods:
OneBusAway Class
agency_with_coverage(get_references: bool = False) -> List[Agency]agency(id: str, get_references: bool = False) -> AgencyDetailsarrival_and_departure_for_stop(id: str, tripId: str, serviceDate: int, vehicleId: Optional[str] = None, stopSequence: Optional[int] = None, get_references: bool = False) -> ArrivalAndDeparturearrivals_and_departures_for_stop(id: str, minutesBefore: Optional[int] = None, minutesAfter: Optional[int] = None, get_references: bool = False) -> StopWithArrivalsAndDeparturesblock(id: str, get_references: bool = False) -> Blockget_config(get_references: bool = False) -> Dict[str, Any]current_time(get_references: bool = False) -> datetimereport_problem_with_stop(stopId: str, code: str, userComment: Optional[str] = None, userLat: Optional[float] = None, userLon: Optional[float] = None, userLocationAccuracy: Optional[float] = None) -> boolreport_problem_with_trip(tripId: str, serviceDate: int, vehicleId: str, stopId: str, code: str, userComment: Optional[str] = None, userOnVehicle: Optional[bool] = None, userVehicleNumber: Optional[str] = None, userLat: Optional[float] = None, userLon: Optional[float] = None, userLocationAccuracy: Optional[float] = None) -> Noneroute_ids_for_agency(id: str, get_references: bool = False) -> List[str]route(id: str, get_references: bool = False) -> Routeroutes_for_agency(id: str, get_references: bool = False) -> List[Route]routes_for_location(lat: float, lon: float, radius: Optional[int] = None, latSpan: Optional[float] = None, lonSpan: Optional[float] = None, query: Optional[str] = None, get_references: bool = False) -> List[Route]schedule_for_route(id: str, date: Optional[str] = None, get_references: bool = False) -> RouteScheduleschedule_for_stop(id: str, date: Optional[str] = None, get_references: bool = False) -> StopScheduleshape(id: str, get_references: bool = False) -> EncodedPolylinestop_ids_for_agency(id: str, get_references: bool = False) -> List[str]stop(id: str, get_references: bool = False) -> Stopstops_for_location(lat: float, lon: float, radius: Optional[int] = None, latSpan: Optional[float] = None, lonSpan: Optional[float] = None, query: Optional[str] = None, get_references: bool = False) -> List[Stop]stops_for_route(id: str, includePolylines: Optional[bool] = None, time: Optional[str] = None, get_references: bool = False) -> StopsForRoutetrip_details(id: str, serviceDate: Optional[int] = None, includeTrip: Optional[bool] = None, includeSchedule: Optional[bool] = None, includeStatus: Optional[bool] = None, time: Optional[str] = None, get_references: bool = False) -> TripDetailstrip_for_vehicle(id: str, includeTrip: Optional[bool] = None, includeSchedule: Optional[bool] = None, includeStatus: Optional[bool] = None, time: Optional[str] = None, get_references: bool = False) -> TripDetailstrip(id: str, get_references: bool = False) -> Triptrips_for_location(lat: float, lon: float, latSpan: float, lonSpan: float, includeTrip: Optional[bool] = None, includeSchedule: Optional[bool] = None, time: Optional[str] = None, get_references: bool = False) -> List[TripDetails]trips_for_route(id: str, includeStatus: Optional[bool] = None, includeSchedule: Optional[bool] = None, time: Optional[str] = None, get_references: bool = False) -> List[TripDetails]vehicles_for_agency(id: str, time: Optional[str] = None, get_references: bool = False) -> List[VehicleStatus]
For detailed information on each method, including parameter descriptions and return types, please refer to the API Documentation.
Contributing
We welcome and appreciate contributions from the community! If you find any issues or have suggestions for improvements, please feel free to submit a pull request or open an issue on the GitHub repository.
To contribute, follow these steps:
- Fork the repository on GitHub.
- Create a new branch for your feature or bug fix:
git checkout -b my-new-feature. - Make your changes and commit them:
git commit -am 'Add some feature'. - Push your changes to your forked repository:
git push origin my-new-feature. - Create a new pull request on the main repository.
Please ensure that your code adheres to the project's coding standards and that all tests pass before submitting a pull request.
License
The OneBusAway Python Client is released under the MIT License.
Support
If you have any questions, or issues, or need further assistance, please open an issue on the GitHub repository or join our discussion forum.
Acknowledgments
The OneBusAway Python Client was inspired by the OneBusAway API and the need for a robust and easy-to-use Python library to interact with it. We would like to express our gratitude to the OneBusAway team and the open-source community for their contributions and support.
Metadata
Release files for onebusaway-unofficial 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| onebusaway_unofficial-1.0.2.tar.gz | 20.6 kB | Without provenance | Details for onebusaway_unofficial-1.0.2.tar.gz |
Release files / onebusaway_unofficial-1.0.2.tar.gz
| Download URL | onebusaway_unofficial-1.0.2.tar.gz |
|---|---|
| Size | 20.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccbd8696ed581a93a2f62b3e26d28c5c8245d20f3415d07903885df25dbe2552
|
|
BLAKE2b-256 checksum How to use checksums |
2893dc69c3ec51cbe2e24063e07f9b99f2a021dc79087a9368b01b1474d9bef2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/40.0 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.66.1 importlib-metadata/6.8.0 keyring/24.2.0 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.14
|
Security for onebusaway-unofficial 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.