https://github.com/strvm/ratp-api-python
Python wrapper for the RATP API.
https://github.com/strvm/ratp-api-python
api metro ratp rer
Last synced: about 2 months ago
JSON representation
Python wrapper for the RATP API.
- Host: GitHub
- URL: https://github.com/strvm/ratp-api-python
- Owner: Strvm
- Created: 2024-01-13T21:41:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-14T23:03:16.000Z (over 1 year ago)
- Last Synced: 2025-04-04T13:50:09.414Z (2 months ago)
- Topics: api, metro, ratp, rer
- Language: Python
- Homepage:
- Size: 15.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RatpAPI Python Wrapper
## Overview
RatpAPI is a Python wrapper for interacting with the RATP (Régie Autonome des Transports Parisiens) API. This library provides easy access to real-time traffic information, line-specific traffic details, and affluence data for journeys on the RATP network in Paris.## Features
- Fetch global traffic information on the RATP network.
- Retrieve traffic information for specific lines using the `LineID` enum for easy reference.
- Get affluence data for journeys on particular lines.
- Utilizes Pydantic models for data validation and parsing.## Installation
To use RatpAPI in your project, you can install it via pip:
```bash
pip install ratp-api-python
```## Usage
a
### Setting Up
First, import the `RatpAPI` class and initialize it with your API key:```python
from ratp_api.main import RatpAPIapi = RatpAPI()
```### Using the LineID Enum
The `LineID` enum provides a convenient way to reference specific lines by their IDs:
```python
from ratp_api.enums import LineID# Example: Using LineID for RER A
line_id = LineID.RER_A
```### Fetching Global Traffic Information
To get global traffic data:
```python
global_traffic = api.get_global_traffic()
print(global_traffic)
```### Fetching Line-Specific Traffic
To get traffic information for a specific line using the `LineID` enum:
```python
line_data = api.get_line_traffic(line_id=LineID.METRO_14)
for situation in line_data.situations:
print(situation)
# Output:
# isActive=True isPlanned=True criticity='HIGH' messages=["Jusqu'au 04/02, le week-end, trafic interrompu sur l'ensemble de la ligne en raison de travaux. Bus de remplacement. Plus d'informations sur la page dédiée."]
# isActive=False isPlanned=True criticity='HIGH' messages=["Du 01/02 au 08/02, du lundi au jeudi à partir de 22h, trafic interrompu sur l'ensemble de la ligne en raison de travaux. Bus de remplacement. Plus d'informations sur la page dédiée."]
# isActive=False isPlanned=True criticity='HIGH' messages=["Jusqu'au 31/01, du lundi au jeudi à partir de 22h, trafic interrompu sur l'ensemble de la ligne en raison de travaux. Bus de remplacement. Plus d'informations sur la page dédiée."]```
### Fetching Affluence for Journeys
To get affluence data for a specific journey on a line:
```python
line_id = LineID.RER_A # Using LineID enumaffluence_data = api.get_line_affluence(line_id=line_id)
print(affluence_data)
```### Fetching Affluence for All Lines
To get affluence data for all lines:
```python
all_lines_affluence = api.get_all_lines_affluence()
print(all_lines_affluence)
```## Contributing
Contributions to the RatpAPI project are welcomed!## License
This project is licensed under the MIT License.---