Skip to main content

Get faster Renfe Spanish Trains timetables in your terminal.

Project description

CICD

Renfe Timetables CLI

Get faster Renfe trains timetables in your terminal, with Python3.8+ support. No longer need to open the browser! Just keep using your terminal 😀

It supports both Horarios de alta velocidad, larga distancia y media distancia (default option, as in the web) and Renfe Cercanías GTFS datasets.

renfe-cli is written in Rust (since v4.0.0) and published to pypi.org as a Python package (CLI and library).

It is provided as a Python package due to historical reasons, but was ported to Rust to showcase Rust's interoperability and performance improvements that can offer to the Python ecosystem. Nevertheless, one can optionally use the built renfe-cli crate that is publised to crates.io.

See the changelog.

NOTE since I am more often using Rodalies trains I have created rodalies-cli. I hope you like it too!

DISCLAIMER: Renfe's GTFS dataset might not be in sync with autonomic train schedules systems (e.g. Rodalies de la Generalitat de Catalunya), hence Renfe Cercanias train types (e.g.: REGIONAL or MD type) might not be accurate, or when using the cercanias flag you won't find timetables for the stations belonging to autonomic systems. For that, please use autonomic data/apps (.e.g: rodalies-cli).

Installation

Python package

Install Python CLI package renfe-cli

pip install renfe-cli --upgrade

Rust crate (optional)

Install the Rust crate renfe-cli

cargo install renfe-cli

Usage (CLI)

The CLI uses the official and latest Renfe's GTFS dataset, from Horarios de alta velocidad, larga distancia y media distancia, by default. Optionally, one can enable searching over Renfe Cercanías GTFS dataset (expect longer load time in this case).

$ renfe-cli -h
Usage: renfe-cli [options]

Options:
    -f ORIGIN           Set From origin station
    -t DESTINATION      Set To destination station
    -d, --day DAY       Set the Day (default: today's day)
    -m, --month MONTH   Set the Month (default: today's month)
    -y, --year YEAR     Set the Year (default: today's year)
    -s, --sort          Option to sort the timetable by Duration
    -c, --cercanias     Option to search over Renfe Cercanías
    -h, --help          Print this help menu

Getting the timetable

Let's show an example of minimal inputs (origin and destination stations) with specific date and default GTFS dataset:

$ renfe-cli  -f girona -t "puerta de atocha" -d 30
Loading default GTFS data from Renfe web - Alta velocidad, Larga distancia y Media distancia
Provided input 'girona' does a match with 'Estación de tren Girona'
Provided input 'puerta de atocha' does a match with 'Estación de tren Madrid-Puerta de Atocha'
Today is: 2024-9-29
Searching timetable for date: 2024-9-30
Origin station: Estación de tren Girona
Destination station: Estación de tren Madrid-Puerta de Atocha

=========================TIMETABLE=========================
  Train        |   Departure  |   Arrival    |   Duration
-----------------------------------------------------------
   AVLO        |    05:46     |    09:20     |    03:34
-----------------------------------------------------------
   AVE         |    06:41     |    10:10     |    03:29
-----------------------------------------------------------
   AVE         |    08:11     |    11:45     |    03:34
-----------------------------------------------------------
   AVE INT     |    11:59     |    15:45     |    03:46
-----------------------------------------------------------
   AVE         |    15:11     |    19:12     |    04:01
-----------------------------------------------------------
   AVE         |    17:51     |    21:45     |    03:54
===========================================================

Let's show an example using Renfe Cercanías GTFS dataset:

$ renfe-cli -f chamartín -t "tres cantos" -c
Loading Cercanías GTFS data from Renfe web - long load time
Provided input 'chamartín' does a match with 'Station { name: "Estación de tren Madrid-Chamartín-Clara Campoamor", id: "17000" }'
Provided input 'tres cantos' does a match with 'Station { name: "Estación de tren Tres Cantos (apt)", id: "17004" }'
Today is: 2024-10-2
Searching timetable for date: 2024-10-2
Origin station: Estación de tren Madrid-Chamartín-Clara Campoamor
Destination station: Estación de tren Tres Cantos (apt)

=========================TIMETABLE=========================
  Train        |   Departure  |   Arrival    |   Duration    
-----------------------------------------------------------
   C4b         |    05:06     |    05:22     |    00:16     
-----------------------------------------------------------
   C4b         |    05:38     |    05:55     |    00:17     
-----------------------------------------------------------
   C4b         |    06:10     |    06:27     |    00:17     
-----------------------------------------------------------
.........
.........
-----------------------------------------------------------
   C4b         |    21:56     |    22:13     |    00:17     
-----------------------------------------------------------
   C4b         |    22:20     |    22:37     |    00:17     
-----------------------------------------------------------
   C4b         |    23:16     |    23:33     |    00:17     
===========================================================

Usage (Library)

renfe-cli can be imported as a python package into your project, offering utilities when willing to deal with the Renfe search web site.

$ python
Python 3.12.6 (main, Sep  8 2024, 13:18:56) [GCC 14.2.1 20240805] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import renfe_cli
>>> renfe = renfe_cli.
renfe_cli.Renfe()    renfe_cli.Schedule(  renfe_cli.Station(   renfe_cli.main()     renfe_cli.renfe_cli  
>>> renfe = renfe_cli.Renfe()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Renfe.__new__() missing 1 required positional argument: 'cercanias'
>>> renfe = renfe_cli.Renfe(False)
Loading default GTFS data from Renfe web - Alta velocidad, Larga distancia y Media distancia
GTFS data:
  Read in 2171 ms
  Stops: 793
  Routes: 644
  Trips: 4150
  Agencies: 1
  Shapes: 0
  Fare attributes: 0
  Feed info: 0
>>> renfe.filter_station("madrid")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Provided input 'madrid' does match with '[Station { name: "Estación de tren Madrid-Puerta de Atocha", id: "60000" }, Station { name: "Estación de tren Madrid - Atocha Cercanias", id: "18000" }, Station { name: "Estación de tren Madrid-Principe Pio", id: "10000" }, Station { name: "Estación de tren Madrid-Ramon Y Cajal", id: "97201" }, Station { name: "Estación de tren Madrid-Nuevos Ministerios", id: "18002" }, Station { name: "Estación de tren Madrid-Chamartin", id: "17000" }, Station { name: "Estación de tren Madrid-Recoletos", id: "18001" }]' -> There must be ONLY one match
>>> renfe.filter_station("girona")
Provided input 'girona' does a match with 'Station { name: "Estación de tren Girona", id: "79300" }'
<builtins.Station object at 0x77f04173d070>
>>> renfe.print_timetable()

No schedules available...won't print timetable.
>>> renfe.set_train_schedules("79300", "60000", 30, 9, 2024, False)
>>> renfe.print_timetable()

=========================TIMETABLE=========================
  Train        |   Departure  |   Arrival    |   Duration
-----------------------------------------------------------
   AVLO        |    05:46     |    09:20     |    03:34
-----------------------------------------------------------
   AVE         |    06:41     |    10:10     |    03:29
-----------------------------------------------------------
   AVE         |    08:11     |    11:45     |    03:34
-----------------------------------------------------------
   AVE INT     |    11:59     |    15:45     |    03:46
-----------------------------------------------------------
   AVE         |    15:11     |    19:12     |    04:01
-----------------------------------------------------------
   AVE         |    17:51     |    21:45     |    03:54
===========================================================
>>> ...

Contribute or Report with Issues

If Renfe's GTFS dataset is being kept not up to date or you find any issue to be fixed or nice enhancements to have, please: create an issue.

Development

This project makes use of Rust bindings for the Python interpreter thanks to pyo3. It is already available as a dependency.

To develop, build and publish, this project makes use of maturin project. See usage.

Example of first time working with this repository:

$ git clone https://github.com/gerardcl/renfe-cli.git && cd renfe-cli
$ python -m venv .venv
$ . .venv/bin/activate
$ pip install -U pip
$ pip install -U maturin
$ maturin develop
🔗 Found pyo3 bindings with abi3 support for Python  3.7
🐍 Not using a specific python interpreter
📡 Using build options features from pyproject.toml
   Compiling renfe-cli v5.1.0 (/path/to/renfe-cli)
    Finished dev [unoptimized + debuginfo] target(s) in 7.07s
📦 Built wheel for abi3 Python  3.7 to /tmp/.tmpDsjowL/renfe_cli-5.1.0-cp37-abi3-linux_x86_64.whl
🛠 Installed renfe-cli-5.1.0

Maturin takes care of compiling the rust code, generating the bindings for python and installing the package for local use (as library or binary/CLI).

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

renfe_cli-5.2.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distributions

renfe_cli-5.2.0-cp37-abi3-win_amd64.whl (2.0 MB view details)

Uploaded CPython 3.7+ Windows x86-64

renfe_cli-5.2.0-cp37-abi3-win32.whl (1.7 MB view details)

Uploaded CPython 3.7+ Windows x86

renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_i686.whl (2.4 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ i686

renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_armv7l.whl (2.4 MB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.4 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.5 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (2.3 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ i686

renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (2.2 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARMv7l

renfe_cli-5.2.0-cp37-abi3-macosx_11_0_arm64.whl (2.0 MB view details)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

renfe_cli-5.2.0-cp37-abi3-macosx_10_12_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.7+ macOS 10.12+ x86-64

File details

Details for the file renfe_cli-5.2.0.tar.gz.

File metadata

  • Download URL: renfe_cli-5.2.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for renfe_cli-5.2.0.tar.gz
Algorithm Hash digest
SHA256 236227f9cacdd4f0899ac846085de3b0603bd0dbb19776484974022e92ff5077
MD5 540770aa850b821d7daa18b280797b10
BLAKE2b-256 f158c351f0b44a3100bba70f8fdf23b1ab29f30560beff1527813aa049b1fd0a

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e57ab17c293f70737132a88c6f8fb273241e3207e41168b08f8532406911a506
MD5 f3590f0a1f0101aa6424e63ffbf9b073
BLAKE2b-256 cde1341aac5e7d60f1f4e485b4d1246916cbb7d49eb0d0f6aa6fba588ef078ed

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-win32.whl.

File metadata

  • Download URL: renfe_cli-5.2.0-cp37-abi3-win32.whl
  • Upload date:
  • Size: 1.7 MB
  • Tags: CPython 3.7+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 45b293fb337ef5b564cca145fe0e76c02ec8fd6fe83d4f28b557be51db750309
MD5 bcad9e54ef4a3d4d176f6941cd5f68a3
BLAKE2b-256 3f7cc3861573ca419d508b12efbdbf5d8ceed6f2265fb0b299744b2849b49a8f

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 37f3806db7ba5fd8f824732b494ac71ff66aa703159195bb8b42cd38a7fee650
MD5 32affab774630994f072ada4fbd175c1
BLAKE2b-256 81dab3c0b81aa206d9579f499fad211c5644449a7bc36757efa396e2347c7777

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f80bc1d343d19fdb907b5bf3f8101e30dc98c555f9476d65b8eb9e1f62fae386
MD5 d8650474b4dd0d04a370f5a99f42ff20
BLAKE2b-256 e653f579b6c05deac098c0e5f09bec5460f7c0caaa9f83f90af148f06a94bdba

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 9c8aa2717148cea77cf5d419c93deef87f3fdd650a2f826c64b8a8a0b77b8882
MD5 a5650128c7ecbe809e5b82836dce83cb
BLAKE2b-256 4269ff39db9ae1f72d97a3e715499b188c51623e16e009227e37b0cc0fe6fa25

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1d58e95116d415e851f2191648ac03e96e07c353a026a485e7fec05f7fe8e81
MD5 dec70ffc40d9bb7a1afa9f69bcd549d0
BLAKE2b-256 92dd5787a417b471a7796d4f3c70f81c5ecbff23269ca652f8b4881f42433e60

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 80e42a83cb1824cfe3e8dcf2df100241ccc4116161b5e186131b552c6f31363e
MD5 9c4288de526ccb61f61ca21061c7073a
BLAKE2b-256 756a43a551867dae7e7fa0d9afff1e0440bc9fd8f739ccfcf1fc3353384d0b4c

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 24d81127069bdd1f68208cbde84bdb91850456280605bc1c80d25b7197cd318c
MD5 48beb67b7ae1b254b9aa88913b83eb83
BLAKE2b-256 f1e53e7e9b6680e89119703fdcdd0a26ae09fba44e933a78577d0ab92fcc0813

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 00437fc58f8d6e8fc371f8c038248c8b5716057283fd76bc0bb6d4309712d4f6
MD5 1599b367f252601a5651e0436d0e9b59
BLAKE2b-256 415f338fb014a3005b4696e732999e09de7eb572ab54462c9b95f79788971172

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 a60b2691df4a529930f91e239fefda1ea8922ba7b442e7804ed1c9a09c7f4bf2
MD5 d957b040511f4bd29a5b5f3915f45e0a
BLAKE2b-256 7ccdaab7cba013872e58cd65834914e8f88c0bb313ae68d6305aaa958cc8659b

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3108ce64d323248364c8fd7fc80a46be9601c27bc5610c93168da08294332c2d
MD5 82da23d6a2194cd612366b1f6202bb14
BLAKE2b-256 0e52eecec2257aeae7e90afc5bdfb857a777aaa655008155bf2d82c314949485

See more details on using hashes here.

File details

Details for the file renfe_cli-5.2.0-cp37-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for renfe_cli-5.2.0-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b022ff23995db6a27d7bcb7a558e4acd0c35bc2105847cc59ec9b85195a490cc
MD5 ad5a7e512ef29ead4e44bea89d4d0104
BLAKE2b-256 ba12d5cac8bbde9a1cfa3c6c67cf3a521380484c838cc36ac75a6458423eaf69

See more details on using hashes here.

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