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
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 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.0.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.0.0
File Size Uploaded
renfe_cli-6.0.0.tar.gz 32.6 kB Details

Built distributions (wheels)

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

Total release size: 41.2 MB

Release files / renfe_cli-6.0.0.tar.gz

Download URL renfe_cli-6.0.0.tar.gz
Size 32.6 kB
Tags Source
SHA-256 checksum
How to use checksums
1a38dcb60bdb6a60af22ca0dd8217dcee85033edee196bed229fa0e75c79a260
BLAKE2b-256 checksum
How to use checksums
1101238ab9933cb3d2f855a89785466a11cae01aa72fc865c2caf7ab2222ec3a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

Download URL renfe_cli-6.0.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
6050e70c53d961792e5d66f2385f926c9d3ee404f2a4c238c46ee84f80991dd7
BLAKE2b-256 checksum
How to use checksums
24d19f505f66a1cf7eccd246d33cd26c2f70bf0ca3e263b1543b9242d8415782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

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

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

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

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

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

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

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

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

Download URL renfe_cli-6.0.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
9b17f23d5d4efce3ff38cf4c20f4911e6082232e87fd2f3915ad3145ed98dfc1
BLAKE2b-256 checksum
How to use checksums
00542c4266cfb6f2958f62f796dbc1d12d151ead4651c231684accf7d7c7aa17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.15.0

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

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

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

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

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

Download URL renfe_cli-6.0.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
5f89726b969c30920fe982cf52db81259af350f934fe75537660fb14033567e0
BLAKE2b-256 checksum
How to use checksums
6ac12f90627a4c5e2ccb68645b0c7cce0f9600ac8681c93498878e0f6d26d4a8
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

6.2.0

15 release files

This release

6.0.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