Skip to main content

Python library to use with Navitia APIs

Project description

navitia-client

Pre-release Build Status Release Build Status Python Version

This repository provides a unofficial Python wrapper to use navitia.io APIs.

⚠️ Version 2.0.0 Breaking Changes

Version 2.0.0 introduces breaking changes with the adoption of Request objects for all API methods. If you're upgrading from v1.x, please see the CHANGELOG for the migration guide.

Pre-requisites

To use this library, you will need an access token from navitia.io.

 Installation

The package is available on PiPy

pip install python-navitia-client

 API support

The library supports the following APIs:

API Supported ? Comment
Coverage
Datasets
Contributors
Inverted geocoding
Public transportation Objects exploration
Autocomplete on Public Transport objects
Autocomplete on geographical objects
Places nearby
Journeys
Isochrones
Route Schedules
Stop Schedules
Terminus Schedules
Departures
Arrivals
Line reports
Traffic reports
Equipment reports Not available to all providers
Freefloating nearby Not available to all providers

Usage

To use this library, you need an authentication token provided by Navitia.io.

Create client instance

Create an instance of the NavitiaClient class with your authentication token:

from navitia_client import NavitiaClient

client = NavitiaClient(auth="YOUR_TOKEN_HERE")

A base URL for Navitia IO is hardcoded and provided to NavitiaClient by default. It can be updated using the base_navitia_url parameter.

Access APIs data

URLs are mapped as properties in the NavitiaClient class. You can find the mapping here.

Simple APIs (Coverage, Datasets, Contributors)

For simple APIs like coverage, datasets, and contributors, you can call methods directly:

# Get coverage information
regions = client.coverage.list_coverage_regions()

# Get datasets for a region
datasets, pagination = client.datasets.list_datasets(region_id="fr-idf")

APIs with Request Objects (Journeys, Places, Schedules, etc.)

Most APIs now use Request objects for better type safety and maintainability:

from navitia_client.entities.request.journey import JourneyRequest
from datetime import datetime

# Create a journey request
request = JourneyRequest(
    from_="stop_area:RAT:SA:GDLYO",
    to_="stop_area:RAT:SA:CHDEG",
    datetime_=datetime(2024, 6, 1, 8, 0),
    count=5
)

# Get journeys
journeys = client.journeys.list_journeys(request=request)

Other examples:

from navitia_client.entities.request.places_nearby import PlacesNearbyRequest

# Places nearby with custom parameters
request = PlacesNearbyRequest(
    distance=1000,
    type=["stop_area", "stop_point"],
    count=20
)
places, pagination = client.places_nearby.list_objects_by_region_id_and_path(
    region_id="fr-idf",
    resource_path="lines/line:RAT:M1",
    request=request
)

Pagination

Several APIs are paginated, particularly the public transportation APIs. You can navigate through results using the start_page and count parameters in Request objects:

from navitia_client.entities.request.journey import JourneyRequest

# Request with pagination
request = JourneyRequest(
    from_="stop_area:RAT:SA:GDLYO",
    to_="stop_area:RAT:SA:CHDEG",
    start_page=0,  # First page
    count=10       # 10 results per page
)

journeys = client.journeys.list_journeys(request=request)

A Pagination object is provided by paginated methods to help you navigate through results.

Tips

Few tips on how to use the Navitia APIs are available here.

 Dependencies

  • Python >= 3.12
  • requests>=2.33

Additional dependencies are described in the pyproject.toml file.

 Contributing

You are free to contribute to the repo. Please read Contributing.md.

 Additional questions

  • Are you affiliated with Navitia ? No. This is an unofficial wrapper for the Navitia.io APIs.

  • Is this client asynchronous ? No, and it is not planned to. If you want to add async support, feel free to contribute.

  • Is this client production ready ? Yes and no. For my own purpose, it is, but I cannot guarantee that everything will behave well. If you spot a bug, please open an issue in the repo.

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

python_navitia_client-3.0.1.tar.gz (39.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_navitia_client-3.0.1-py3-none-any.whl (93.1 kB view details)

Uploaded Python 3

File details

Details for the file python_navitia_client-3.0.1.tar.gz.

File metadata

  • Download URL: python_navitia_client-3.0.1.tar.gz
  • Upload date:
  • Size: 39.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for python_navitia_client-3.0.1.tar.gz
Algorithm Hash digest
SHA256 b83ee94264bd7ed5ecac55d30cab5f8d846cc328a6f1491c260ade0b6dc58ebe
MD5 18c398f1aa043a9f44c1234ed4eb4b92
BLAKE2b-256 024ecbd4c46cc73f4b4bdf28a4264d32d10b0deb6251e6cab8d5acfb3ef2ff37

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_navitia_client-3.0.1.tar.gz:

Publisher: release.yaml on jonperron/python-navitia-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_navitia_client-3.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_navitia_client-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f525d95d6700298f3401409e76d4099a5cb0e11bb028cf4b6a6cb1fa77bb5e34
MD5 9ddbce294730fbe38cd2eec43e0c1241
BLAKE2b-256 9ab43b11e66b740a02047914739905e671086e08912104405d254f0b22051160

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_navitia_client-3.0.1-py3-none-any.whl:

Publisher: release.yaml on jonperron/python-navitia-client

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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