Skip to main content

Get RATP data from RATP API.

Project description

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:

pip install ratp-api-python

Usage

a

Setting Up

First, import the RatpAPI class and initialize it with your API key:

from ratp_api.main import RatpAPI

api = RatpAPI()

Using the LineID Enum

The LineID enum provides a convenient way to reference specific lines by their IDs:

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:

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:

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:

line_id = LineID.RER_A          # Using LineID enum

affluence_data = api.get_line_affluence(line_id=line_id)
print(affluence_data)

Fetching Affluence for All Lines

To get affluence data for all lines:

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.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ratp_api-1.0.3.tar.gz (8.2 kB view hashes)

Uploaded Source

Built Distribution

ratp_api-1.0.3-py3-none-any.whl (7.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page