Skip to main content

CICD

Renfe Timetables CLI

Get faster Renfe trains timetables in your terminal, with Python 3.10+ 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. Timetable searches include connections with up to three transfers. The router favors shorter journeys and applies a transfer penalty so a marginal time saving does not produce an unnecessarily complicated itinerary.

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

uv tool 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
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
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     
===========================================================

Selecting a station

Station names are matched case-insensitively and may be abbreviated. If the provided text matches more than one station, the CLI sorts the matches by name and asks which station to use. Select it by entering its 1-based ordinal number:

$ renfe-cli -f madrid -t girona
Multiple stations match 'madrid':
  1. Estación de tren Madrid - Atocha Cercanias
  2. Estación de tren Madrid-Chamartin
  3. Estación de tren Madrid-Nuevos Ministerios
  4. Estación de tren Madrid-Principe Pio
  5. Estación de tren Madrid-Puerta de Atocha
  6. Estación de tren Madrid-Ramon Y Cajal
  7. Estación de tren Madrid-Recoletos
Select a station [1-7]: 5

Invalid numbers are rejected and the CLI asks again. If the provided text does not match any station, it reports the input without presenting a selection:

ValueError: Provided input 'unknown' does not match any station name

Journeys with connections include the details of every transfer directly below the timetable row. The arrival and departure are the times at which the transfer starts and ends; the duration is the total time available to change trains. Transfers between different stops show both station names:

      Transfer 1 at Madrid-Chamartín: arrive 10:05, depart 10:20 (00:15)
      Transfer 2 at Madrid-Atocha → Madrid-Puerta de Atocha: arrive 10:45, depart 11:10 (00:25)

Downloaded feeds are converted to routing data and cached in the operating system's user cache directory. On later runs, renfe-cli sends Renfe the stored HTTP ETag; when the feed has not changed, Renfe returns 304 Not Modified and the processed data is loaded directly from the local cache. Set RENFE_CLI_CACHE_DIR to use a custom cache location.

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
>>> len(renfe.stations_match("madrid"))
7
>>> len(renfe.stations_match("girona"))
1
>>> 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 uses Rust bindings for the Python interpreter through PyO3 and Maturin to build and install the Python package.

Install uv first, then set up a development environment:

git clone https://github.com/gerardcl/renfe-cli.git
cd renfe-cli
uv python install 3.10
uv venv --python 3.10
source .venv/bin/activate
uvx maturin develop --uv

Maturin compiles the Rust code, generates the Python bindings, and installs the package into .venv for local use as a library or CLI. After changing Rust code, run uvx maturin develop --uv again to rebuild it. Use uv run renfe-cli --help to run the development installation.

Release files for renfe-cli 6.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for renfe-cli 6.2.0
File Size Uploaded
renfe_cli-6.2.0.tar.gz 38.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for renfe-cli 6.2.0
File
renfe_cli-6.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
renfe_cli-6.2.0-cp310-abi3-win32.whl CPython 3.10 abi3 Windows x86-32 Details
renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_i686.whl CPython 3.10 abi3 Linux musl 1.2+ x86-32 Details
renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_armv7l.whl CPython 3.10 abi3 Linux musl 1.2+ ARMv7l Details
renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl CPython 3.10 abi3 Linux glibc 2.17+ IBM System/390x Details
renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl CPython 3.10 abi3 Linux glibc 2.17+ PowerPC 64-le Details
renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-32 Details
renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.10 abi3 Linux glibc 2.17+ ARMv7l Details
renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
renfe_cli-6.2.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
renfe_cli-6.2.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 42.1 MB

Release files / renfe_cli-6.2.0.tar.gz

Download URL renfe_cli-6.2.0.tar.gz
Size 38.1 kB
Tags Source
SHA-256 checksum
How to use checksums
307240e0358f1ff352c458d4cb46f4b8d3f80f9bad71b6856dcff6cb8d8d012f
BLAKE2b-256 checksum
How to use checksums
cbf09b0bdb0d323188fee8a75f16bde42427ebc3ee1c4c31e31419b8e3259302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-win_amd64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-win_amd64.whl
Size 2.5 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
83c059db6792c555832c19e8612fe4f865bdf99c32c9614b375ab7242531077b
BLAKE2b-256 checksum
How to use checksums
a10d4b06abfe8bdaf40ac405f55a770a304b40a1b5cfb1548daf1b81ad1c1302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-win32.whl

Download URL renfe_cli-6.2.0-cp310-abi3-win32.whl
Size 2.2 MB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
78aa7e9cddfdfc298eb37440e63bf5c4ec8787e88b8530362f8cfff7a9bd1a0e
BLAKE2b-256 checksum
How to use checksums
58fa74c224d7f91e598d806f228f01de390924d4b53a73b63bff21738774a09f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_x86_64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_x86_64.whl
Size 3.5 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
9d320d5cac533995b45e309b6c2467107108d76e0836560586514438634d5ced
BLAKE2b-256 checksum
How to use checksums
f188171a2556d8487f8b855472674bb9e8da1377941cff0c888244fd6be6cb9f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_i686.whl

Download URL renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_i686.whl
Size 3.1 MB
Tags CPython 3.10 Linux musl 1.2+ x86-32 abi3
SHA-256 checksum
How to use checksums
e5fd60bc567f542161808e414ec98a69fefd6536bf322e1d2cfca68fc7ee486b
BLAKE2b-256 checksum
How to use checksums
a60d6713ff3a2fc7c887259d6c0dfdd9bdd0b666dc8c0905cd53ae1c638d98d1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_armv7l.whl

Download URL renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_armv7l.whl
Size 3.0 MB
Tags CPython 3.10 Linux musl 1.2+ ARMv7l abi3
SHA-256 checksum
How to use checksums
45f630db2e8ac22a75959e2704a03fffde5596b5fc7f7c062df4a368eec54cc9
BLAKE2b-256 checksum
How to use checksums
efd83f43ce9bfc435b9853807092cba1c0907fe602fdadfade128f807bae7592
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_aarch64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 3.3 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
120294742d801c15a105d3dc2f996427aeb0b045cc9524fd494a38333559a615
BLAKE2b-256 checksum
How to use checksums
24d5fe8d19388cc70e0d53ce613f11ed4dc9c6e9f7c0ee401f8351afd2b588a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 3.2 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
a6cee2eebbd82d2e8721dbbd01f17653e6e36f43cd0e6d26dd709bda6b4f4984
BLAKE2b-256 checksum
How to use checksums
b336d6041b3aa3b71057ce403e9f0a8a634cacfdb957fa7e9a82ae09d0dd87bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl

Download URL renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Size 2.9 MB
Tags CPython 3.10 Linux glibc 2.17+ IBM System/390x abi3
SHA-256 checksum
How to use checksums
464e4cecc56b4e72bd9ccee5b6f523067daed062f413c8918a95bc83e32ddab6
BLAKE2b-256 checksum
How to use checksums
a599e41a40c21821e1bbeda10384632b6f598560510632ad013ca22b3f5bb2b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Download URL renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Size 3.5 MB
Tags CPython 3.10 Linux glibc 2.17+ PowerPC 64-le abi3
SHA-256 checksum
How to use checksums
a2c26406e112fc82329866a9810b5a402b7593de0659990318205259c4178180
BLAKE2b-256 checksum
How to use checksums
e0c38892c5bba31b7d38a971c6bc629efb9e3dac890d44322249f9e4d595c1f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl

Download URL renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
Size 3.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-32 abi3
SHA-256 checksum
How to use checksums
9f41b1cfe02f1e51b4e6585713c7e4fcc0363ba492b1c8eb9fed1e85747fe5d0
BLAKE2b-256 checksum
How to use checksums
cbf2d45ba15a4b331b3e92e6b43732fc0517bbe9b8cacb6aaf4143227166b474
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl

Download URL renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Size 2.7 MB
Tags CPython 3.10 Linux glibc 2.17+ ARMv7l abi3
SHA-256 checksum
How to use checksums
3c7d98c6602f9870e0f8244d8b7271b71b2b819fd34b6725c229d81d0681ca67
BLAKE2b-256 checksum
How to use checksums
29619a795f2237fda7f85d8eb5c364dafa2ef1d6b12c0ad45cadec05ba434a73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.2 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
5caf0dc194dfc2b4b7811dcc715a2ad5edfccfdc364b09bf6416a829d3fdaa86
BLAKE2b-256 checksum
How to use checksums
a1093e8d4214634c926e20ae30025be72e1d2a2ea5567401109948e4cee56626
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-macosx_11_0_arm64.whl
Size 2.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7ba6232f82d6d3e362a5011ededc08a010806a108345254d52cc0eeaad06ea97
BLAKE2b-256 checksum
How to use checksums
f24e7ef2812a00011e04c65502f6d09131ca0fd479db85a052e1ff912e848061
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release files / renfe_cli-6.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL renfe_cli-6.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f9f00c9035c4ab39474954ff8ac0ba0ef650fd7ab50917b5fc303dbc60f89982
BLAKE2b-256 checksum
How to use checksums
39230b4fbc567dbde0bba43472059d711dad9effe329e0e14ed877d427ca1924
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

Release history Release notifications | RSS feed

6.3.0

15 release files

This release

6.2.0 This release

15 release files

5.0.0

10 release files

4.3.1

10 release files

4.3.0

10 release files

4.2.0

10 release files

4.1.0

10 release files

4.0.0

10 release files

3.3.0

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.0

3 release files

1.1.7

3 release files

1.1.6

3 release files

1.1.5

3 release files

1.1.4

3 release files

1.1.3

3 release files

1.1.2

4 release files

1.1.1

1 release file

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page