Asynchronous API client for interaction with the CTS api.
Project description
CTS API Client
An asynchronous Python client for the CTS (Compagnie des Transports Strasbourgeois) API.
Installation
You can install this library from the repository:
pip install git+https://github.com/theggz/cts-api.git
Usage
First, you need to get an API token from the CTS API website.
Then, you can initialize the client and make API calls:
import asyncio
from cts_api.client import CtsApi
async def main():
# Initialize the client with your API token
# Make sure to replace "YOUR_API_TOKEN" with your actual token
api = CtsApi(token="YOUR_API_TOKEN", session=None)
# Example: Get all lines
lines_response = await api.lines_discovery()
for line in lines_response.lines_delivery.annotated_line_refs:
print(f"Line {line.line_name} ({line.line_ref})")
# Example: Get stop points near a location
stop_points_response = await api.stoppoints_discovery(
latitude=48.583,
longitude=7.75,
distance=500
)
for stop in stop_points_response.stop_points_delivery.annotated_stop_point_ref:
print(f"Stop: {stop.stop_name}")
# Example: Get next departures for a stop
stop_monitoring_response = await api.stop_monitoring(monitoring_ref="280a")
for visit in stop_monitoring_response.service_delivery.stop_monitoring_delivery[0].monitored_stop_visit:
journey = visit.monitored_vehicle_journey
print(
f"Line {journey.published_line_name} to {journey.destination_name}: "
f"at {journey.monitored_call.expected_departure_time}"
)
if __name__ == "__main__":
asyncio.run(main())
API Methods
All methods are async and raise exceptions derived from CtsError on failure.
-
CtsApi(token, session=None): Constructor.tokenis your API key.sessionis an optionalaiohttp.ClientSession. -
lines_discovery(): Returns a list of all lines. -
stoppoints_discovery(latitude, longitude, distance, stop_code=None, ...): Returns a list of stop points. Can search by coordinates and distance, or by stop code. -
stop_monitoring(monitoring_ref, ...): Provides a stop-centric view of vehicle departures (real-time) at a designated stop.monitoring_refis typically a stop code. -
general_messages(): Returns messages about traffic, services, commercial information, etc.
Running Tests
To run the tests, first clone the repository and install the development dependencies:
git clone https://github.com/theggz/cts-api.git
cd cts-api
pip install -e .
pip install pytest pytest-asyncio faker
Unit Tests
The unit tests mock the API and can be run without an API token:
pytest
Integration Tests
The integration tests run against the live CTS API and require a valid API token.
-
Set your API token as an environment variable:
export CTS_API_TOKEN="YOUR_API_TOKEN"
-
Run the tests marked as
integration:pytest -m integration
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cts_api-0.0.2.tar.gz.
File metadata
- Download URL: cts_api-0.0.2.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ec6e1c4ae4393f33447902fd85335b5f9758dfb1a7d44157294036b892a438a1
|
|
| MD5 |
10ef99d4f9fa3d4c65e8996d1bd60fcb
|
|
| BLAKE2b-256 |
1c93edaa2a8a797bb60d859fe3abb0b647615c2ddb816e5d1fa16c642e64c8f1
|
File details
Details for the file cts_api-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cts_api-0.0.2-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c540f287d4e5eeeaa562158add784e036aaf63e69c3817dc382e4215fcff2c
|
|
| MD5 |
bb8e7dd69e8dd8815c8399872b8aa98e
|
|
| BLAKE2b-256 |
85d33093f47ed2311ecb5e66c6a848b93f1d3bb2931afd04e93d63b967f28fb2
|