bods-client
A Python client for the Department for Transport Bus Open Data Service API
Installation
pip install bods-client
Example
GTFS RT
All the vehicle locations for vehicles in a geographical location can be obtained
using the get_gtfs_rt_data_feed method with a bounding box.
from bods_client.client import BODSClient
from bods_client.models import BoundingBox, GTFSRTParams
# An API key can be obtained by registering with the Bus Open Data Service
# https://data.bus-data.dft.gov.uk/account/signup/
>> API_KEY = "api-key"
>> bods = BODSClient(api_key=API_KEY)
>> bounding_box = BoundingBox(
**{
"min_latitude": 51.26,
"max_latitude": 51.75,
"min_longitude": -0.54,
"max_longitude": 0.27,
}
)
>> params = GTFSRTParams(bounding_box=bounding_box)
>> message = bods.get_gtfs_rt_data_feed(params=params)
>> message.entity[0]
id: "421354378097713049"
vehicle {
trip {
trip_id: ""
route_id: ""
}
position {
latitude: 51.712860107421875
longitude: -0.38401100039482117
bearing: 170.0
}
timestamp: 1614396229
vehicle {
id: "7214"
}
}
This returns a google.transit.gtfs_realtime_pb2.FeedMessage object. More details about
General Transit Feed Specification Realtime Transit (GTFS-RT) can be found
here.
SIRI VM
Vehicle locations are also provided in the SIRI-VM XML format using the
get_siri_vm_data_feed method. The data can then parsed using an xml
parser library such as lxml.
from bods_client.client import BODSClient
from bods_client.models import BoundingBox, Siri, SIRIVMParams
>> API_KEY = "api-key"
>> client = BODSClient(api_key=API_KEY)
>> bounding_box = BoundingBox(
**{
"min_latitude": 51.267729,
"max_latitude": 51.283191,
"min_longitude": -0.142423,
"max_longitude": 0.177432,
}
)
>> params = SIRIVMParams(bounding_box=bounding_box)
>> siri_response = client.get_siri_vm_data_feed(params=params)
>> siri = Siri.from_bytes(siri_response)
>> siri.service_delivery.vehicle_monitoring_delivery.vehicle_activities[0]
VehicleActivity(
recorded_at_time=datetime.datetime(
2022, 1, 31, 19, 48, 24, tzinfo=datetime.timezone.utc
),
item_identifier="05fc46f3-9629-4336-9a8d-f397030f5891",
valid_until_time=datetime.datetime(2022, 1, 31, 21, 5, 21, 997139),
monitored_vehicle_journey=MonitoredVehicleJourney(
bearing=135.0,
block_ref=None,
framed_vehicle_journey_ref=None,
vehicle_journey_ref="447183",
destination_name="BEDDINGTON (ABELLIO LONDON)",
destination_ref=None,
orgin_name=None,
origin_ref="40004410084D",
origin_aimed_departure_time=datetime.datetime(
2022, 1, 31, 19, 53, tzinfo=datetime.timezone.utc
),
direction_ref="1",
published_line_name="407",
line_ref="296",
vehicle_location=VehicleLocation(longitude=-0.077464, latitude=51.282658),
operator_ref="TFLO",
vehicle_ref="16085",
),
)
Details about the SIRI specification can be found here.
License
Metadata
Release files for bods-client 0.14.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bods_client-0.14.0.tar.gz | 1.0 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| bods_client-0.14.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.0 MB
Release files / bods_client-0.14.0.tar.gz
| Download URL | bods_client-0.14.0.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f315fe6bc2af3549ed8b3cbd26ff3ea92cbabaa659074279c80069908116bdc
|
|
BLAKE2b-256 checksum How to use checksums |
ec8bafa5f143c33553a13f59bccd24c82aaa916e20636a94ea5ddc8874b12b40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.4
|
Release files / bods_client-0.14.0-py3-none-any.whl
| Download URL | bods_client-0.14.0-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de5e98651687fba4d6892759dc15474c50edb887d27507958430224560a4ba03
|
|
BLAKE2b-256 checksum How to use checksums |
0d11782e98deb4d13bb4d456a94dc905f5a1b1a1c8cae56f1f5ad9217faf185a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.6.4
|