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
    -V, --version       Print version information

At startup, renfe-cli prints its running version and checks for a newer release. Python installations check PyPI, while the native Rust binary checks crates.io. Use renfe-cli --version to print only the running version.

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.

This project uses Just as the command runner for local development.

Prerequisites

Make sure the following stack is installed:

[Rust](https://www.rust-lang.org/)
[uv](https://docs.astral.sh/uv/getting-started/installation/)
[Just](https://github.com/casey/just)
[prek](https://prek.j178.dev/)

Setup and workflows

git clone https://github.com/gerardcl/renfe-cli.git
cd renfe-cli
just dev-setup
just # to see available commands

Release files for renfe-cli 6.3.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.3.0
File Size Uploaded
renfe_cli-6.3.0.tar.gz 41.1 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for renfe-cli 6.3.0
File
renfe_cli-6.3.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
renfe_cli-6.3.0-cp310-abi3-win32.whl CPython 3.10 abi3 Windows x86-32 Details
renfe_cli-6.3.0-cp310-abi3-musllinux_1_2_x86_64.whl CPython 3.10 abi3 Linux musl 1.2+ x86-64 Details
renfe_cli-6.3.0-cp310-abi3-musllinux_1_2_i686.whl CPython 3.10 abi3 Linux musl 1.2+ x86-32 Details
renfe_cli-6.3.0-cp310-abi3-musllinux_1_2_armv7l.whl CPython 3.10 abi3 Linux musl 1.2+ ARMv7l Details
renfe_cli-6.3.0-cp310-abi3-musllinux_1_2_aarch64.whl CPython 3.10 abi3 Linux musl 1.2+ ARM64 Details
renfe_cli-6.3.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.3.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.3.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.3.0-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-32 Details
renfe_cli-6.3.0-cp310-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl CPython 3.10 abi3 Linux glibc 2.17+ ARMv7l Details
renfe_cli-6.3.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
renfe_cli-6.3.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
renfe_cli-6.3.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 43.0 MB

Release files / renfe_cli-6.3.0.tar.gz

Download URL renfe_cli-6.3.0.tar.gz
Size 41.1 kB
Tags Source
SHA-256 checksum
How to use checksums
105a2952254a058ef8f05784edbccaa88a0c7ae4fa466bb39b9486ac219023b8
BLAKE2b-256 checksum
How to use checksums
1087e69b2d05acb515a4ae53469b1325fd48ca6b0e41364e1a1be50b4fed1dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

Download URL renfe_cli-6.3.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
eb191b74ea943788b16678505c5c227b56d49b11bf26239096e42c6ddf5282eb
BLAKE2b-256 checksum
How to use checksums
1e52c48c1dca675012d01d8d293386631c1610e3d4c5859f2800b9ae06f11851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

Download URL renfe_cli-6.3.0-cp310-abi3-musllinux_1_2_aarch64.whl
Size 3.4 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
3afe9c509d6fffd7c20f62463476fa7c3e167bcee1b2866381ac048d0be625bc
BLAKE2b-256 checksum
How to use checksums
b0339d0f6dc5f6750a66856acdf9f51acc90807addb4529a2deaba1374be942e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

Download URL renfe_cli-6.3.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
8db0cacf10ad4521b810b4b2e38cfdefbc4d0d32cd229ca4f371afba33c5754a
BLAKE2b-256 checksum
How to use checksums
6cc8914171ce4f34724ad17cab84aa980f25a7593439c1adfa62c080a05cbd9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

Download URL renfe_cli-6.3.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
dd553dc37114af5808cd9bb7c3ac8f2b26fcd8065e9eded3b7457b7bb5e25137
BLAKE2b-256 checksum
How to use checksums
72e2642a333347ff8a9d641e5460a614e7b2a06550b8d6e94a6fda68bbbf75cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

Release history Release notifications | RSS feed

This release

6.3.0 This release

15 release files

6.2.0

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