# bods-client
[![Build Status](https://github.com/ciaranmccormick/python-bods-client/workflows/test/badge.svg?branch=main&event=push)](https://github.com/ciaranmccormick/python-bods-client/actions?query=workflow%3Atest)
[![codecov](https://codecov.io/gh/ciaranmccormick/python-bods-client/branch/main/graph/badge.svg)](https://codecov.io/gh/ciaranmccormick/python-bods-client)
[![Python Version](https://img.shields.io/pypi/pyversions/bods-client.svg)](https://pypi.org/project/bods-client/)
A Python client for the Department for Transport Bus Open Data Service API
## Installation
```bash
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.
```python
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](https://developers.google.com/transit/gtfs-realtime/).
### 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`.
```python
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](http://www.transmodel-cen.eu/standards/siri/).
## License
[MIT](https://github.com/ciaran.mccormick/bods-client/blob/master/LICENSE)
Raw data
{
"_id": null,
"home_page": "https://github.com/ciaranmccormick/python-bods-client",
"name": "bods-client",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "BODS,bus,open data,TXC,transxchange",
"author": "Ciaran McCormick",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/a4/30/df33e81ba08e4416c1f98cdae8b53f9381749c3014cdc34561b1c90f1217/bods_client-0.12.0.tar.gz",
"platform": null,
"description": "# bods-client\n\n[![Build Status](https://github.com/ciaranmccormick/python-bods-client/workflows/test/badge.svg?branch=main&event=push)](https://github.com/ciaranmccormick/python-bods-client/actions?query=workflow%3Atest)\n[![codecov](https://codecov.io/gh/ciaranmccormick/python-bods-client/branch/main/graph/badge.svg)](https://codecov.io/gh/ciaranmccormick/python-bods-client)\n[![Python Version](https://img.shields.io/pypi/pyversions/bods-client.svg)](https://pypi.org/project/bods-client/)\n\nA Python client for the Department for Transport Bus Open Data Service API\n\n\n## Installation\n\n```bash\npip install bods-client\n```\n\n\n## Example\n\n\n### GTFS RT\n\nAll the vehicle locations for vehicles in a geographical location can be obtained\nusing the `get_gtfs_rt_data_feed` method with a bounding box.\n\n```python\n\nfrom bods_client.client import BODSClient\nfrom bods_client.models import BoundingBox, GTFSRTParams\n\n# An API key can be obtained by registering with the Bus Open Data Service\n# https://data.bus-data.dft.gov.uk/account/signup/\n>> API_KEY = \"api-key\"\n\n>> bods = BODSClient(api_key=API_KEY)\n>> bounding_box = BoundingBox(\n **{\n \"min_latitude\": 51.26,\n \"max_latitude\": 51.75,\n \"min_longitude\": -0.54,\n \"max_longitude\": 0.27,\n }\n)\n>> params = GTFSRTParams(bounding_box=bounding_box)\n>> message = bods.get_gtfs_rt_data_feed(params=params)\n>> message.entity[0]\nid: \"421354378097713049\"\nvehicle {\n trip {\n trip_id: \"\"\n route_id: \"\"\n }\n position {\n latitude: 51.712860107421875\n longitude: -0.38401100039482117\n bearing: 170.0\n }\n timestamp: 1614396229\n vehicle {\n id: \"7214\"\n }\n}\n\n```\n\nThis returns a `google.transit.gtfs_realtime_pb2.FeedMessage` object. More details about\nGeneral Transit Feed Specification Realtime Transit (GTFS-RT) can be found\n[here](https://developers.google.com/transit/gtfs-realtime/).\n\n\n### SIRI VM\n\nVehicle locations are also provided in the SIRI-VM XML format using the\n`get_siri_vm_data_feed` method. The data can then parsed using an xml\nparser library such as `lxml`.\n\n```python\nfrom bods_client.client import BODSClient\nfrom bods_client.models import BoundingBox, Siri, SIRIVMParams\n\n\n>> API_KEY = \"api-key\"\n\n>> client = BODSClient(api_key=API_KEY)\n>> bounding_box = BoundingBox(\n **{\n \"min_latitude\": 51.267729,\n \"max_latitude\": 51.283191,\n \"min_longitude\": -0.142423,\n \"max_longitude\": 0.177432,\n }\n)\n\n>> params = SIRIVMParams(bounding_box=bounding_box)\n>> siri_response = client.get_siri_vm_data_feed(params=params)\n>> siri = Siri.from_bytes(siri_response)\n>> siri.service_delivery.vehicle_monitoring_delivery.vehicle_activities[0]\nVehicleActivity(\n recorded_at_time=datetime.datetime(\n 2022, 1, 31, 19, 48, 24, tzinfo=datetime.timezone.utc\n ),\n item_identifier=\"05fc46f3-9629-4336-9a8d-f397030f5891\",\n valid_until_time=datetime.datetime(2022, 1, 31, 21, 5, 21, 997139),\n monitored_vehicle_journey=MonitoredVehicleJourney(\n bearing=135.0,\n block_ref=None,\n framed_vehicle_journey_ref=None,\n vehicle_journey_ref=\"447183\",\n destination_name=\"BEDDINGTON (ABELLIO LONDON)\",\n destination_ref=None,\n orgin_name=None,\n origin_ref=\"40004410084D\",\n origin_aimed_departure_time=datetime.datetime(\n 2022, 1, 31, 19, 53, tzinfo=datetime.timezone.utc\n ),\n direction_ref=\"1\",\n published_line_name=\"407\",\n line_ref=\"296\",\n vehicle_location=VehicleLocation(longitude=-0.077464, latitude=51.282658),\n operator_ref=\"TFLO\",\n vehicle_ref=\"16085\",\n ),\n)\n```\n\nDetails about the SIRI specification can be found [here](http://www.transmodel-cen.eu/standards/siri/).\n\n\n## License\n\n[MIT](https://github.com/ciaran.mccormick/bods-client/blob/master/LICENSE)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python client for the Department for Transport Bus Open Data Service API",
"version": "0.12.0",
"project_urls": {
"Homepage": "https://github.com/ciaranmccormick/python-bods-client",
"Repository": "https://github.com/ciaranmccormick/python-bods-client"
},
"split_keywords": [
"bods",
"bus",
"open data",
"txc",
"transxchange"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9f8b7fb83fdf5015d23d49ab3868149d27b634a0ed3824af0a49433444a49643",
"md5": "8f601656fa7c5d4aaac895160e3818db",
"sha256": "76901b1b9a814a4cd443186a1d306da5dead7a1c36f90464d0bcefbd4eaf7f35"
},
"downloads": -1,
"filename": "bods_client-0.12.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8f601656fa7c5d4aaac895160e3818db",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 11463,
"upload_time": "2023-06-19T18:46:05",
"upload_time_iso_8601": "2023-06-19T18:46:05.393417Z",
"url": "https://files.pythonhosted.org/packages/9f/8b/7fb83fdf5015d23d49ab3868149d27b634a0ed3824af0a49433444a49643/bods_client-0.12.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a430df33e81ba08e4416c1f98cdae8b53f9381749c3014cdc34561b1c90f1217",
"md5": "c66302736045855c28112c215504b759",
"sha256": "f968848e940cdee9c1aa0faef6b41240b0a15e44fa57f1d9b029ff24241cebb2"
},
"downloads": -1,
"filename": "bods_client-0.12.0.tar.gz",
"has_sig": false,
"md5_digest": "c66302736045855c28112c215504b759",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 10021,
"upload_time": "2023-06-19T18:46:06",
"upload_time_iso_8601": "2023-06-19T18:46:06.915221Z",
"url": "https://files.pythonhosted.org/packages/a4/30/df33e81ba08e4416c1f98cdae8b53f9381749c3014cdc34561b1c90f1217/bods_client-0.12.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-19 18:46:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ciaranmccormick",
"github_project": "python-bods-client",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "bods-client"
}