A Python client for the Department for Transport Bus Open Data Service API
Project description
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 boundng 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)
>> box = BoundingBox(min_longitude=-0.54, min_latitude=51.26, max_longitude=0.27, max_latitide=51.75)
>> params = GTFSRTParams(bounding_box=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, SIRIVMParams
from lxml import etree
# 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)
>> box = BoundingBox(min_longitude=-0.54, min_latitude=51.26, max_longitude=0.27,
max_latitide=51.75)
>> params = SIRIVMParams(bounding_box=box)
>> siri = bods.get_siri_vm_data_feed(params=params)
>> siri
b'<Siri xmlns="http://www.siri.org.uk/siri" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.siri.org.uk/siri http://www.siri.org.uk/schema/2.0/xsd/siri.xsd" version="2.0"><ServiceDelivery><ResponseTimestamp>2021-03-16T20:21:25.019277+00:00</ResponseTimestamp><ProducerRef>ItoWorld</ProducerRef><VehicleMonitoringDelivery><ResponseTimestamp>2021-03-16T20:21:25.019277+00:00</ResponseTimestamp><RequestMessageRef>d497da8c-1f05-4db0-8680-dadfb22939b5</RequestMessageRef><ValidUntil>2021-03-16T20:26:25.019277+00:00</ValidUntil>
...
<DriverRef>111133</DriverRef></VehicleJourney></Extensions></VehicleActivity></VehicleMonitoringDelivery></ServiceDelivery></Siri>'
>> xml = etree.parse(siri)
Details about the SIRI specification can be found here.
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for bods_client-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6f0ed2ef05cfd6d3f98b6de201d68417162f9fe395329dac7b155fe64ed21a3 |
|
MD5 | c6cc1753083a216fed640daf01e314f7 |
|
BLAKE2b-256 | 8844d59607060c06949baea0c6a6f1514aa0a6342a7bdb69d2a06c86798d516b |