Skip to main content

rsp-fares-feed

PyPI Python CI Licence: GPL-3.0

Parse the RSP Fares and Associated Data Feed, every permanent rail fare published in Great Britain, into a table you can query.

The Rail Delivery Group and Rail Settlement Plan publish the feed. It arrives as a 300 MB zip of fixed-width text files with no delimiters and no headers, where each field is identified by its character position in a PDF specification. Prices are in pence, stations are NLC numbers, ticket types are three-letter codes, and about 7.6 million fares are spread across two record types that have to be joined by ID. Many fares are not even filed under a station: they belong to a cluster or a group of stations, so looking up the two stations' own codes misses them.

from pathlib import Path
from rsp_fares_feed import clean_feed, build_fares_table, lookup_pair

clean_feed(Path("fares-raw"), Path("fares"))
table = build_fares_table(Path("fares"))
lookup_pair(table, "LIV", "MAN")

Install

Python 3.11 or later.

pip install rsp-fares-feed

or, from a clone, pip install .. It depends on pandas. HTTP goes through urllib from the standard library.

Getting the feed

You need a free National Rail Data Portal account.

export NRDP_USERNAME="you@example.com"
export NRDP_PASSWORD="..."

rsp-fares-feed download -o fares-raw
rsp-fares-feed clean fares-raw -o fares

Credentials are read only from the environment. There is no --password flag and no config setting for one, so they cannot end up in shell history or a committed config file.

RSPS5045 specifies the format, and the Open Rail Data wiki has background on the feed as a whole.

Cleaning the national feed gives:

$ rsp-fares-feed clean fares-raw -o fares
flow        7,612,617
locations       3,449
tickets         3,448
clusters       44,946

Looking up fares

$ rsp-fares-feed lookup LIV MAN -d fares
LIV -> MAN
ticket_code ticket_description  fare_gbp restriction_code toc route_code
        DGA       SALE ADVANCE       0.5               NT NTH      00429
        DGB       SALE ADVANCE       1.0               NT NTH      00429
        DGC       SALE ADVANCE       2.0               NT NTH      00429
        NAP    FOR TEST USE ON       2.3               NT NTH      00429
        DG0            ADVANCE       2.7               NT NTH      00429
        DG1            ADVANCE       3.2               NT NTH      00429
        2AS            ADVANCE       3.7               AS SMA      00472
...
        7DF    SEVEN DAY   1ST     133.0              NaN TPE      00000
        FL1       Flexi Season     139.7              NaN NTH      00083
        FL1       Flexi Season     172.9              NaN TPE      00000

Median adult standard fare per journey: £9.47
Median standard-class Advance: £7.40

The real output has 178 retail fares; the middle is cut here. Add --json for machine-readable output, or --csv out.csv to write a file.

Cluster and group fares

A fare can be set for a cluster of stations (an NLC such as Q814) or a group (1072, LONDON TERMINALS) instead of a single station. The .FSC file lists the clusters, and the .LOC file's member records list the groups. build_fares_table works out every code each station is priced under, and lookup_pair searches all of them.

It makes a large difference. Looking up only the stations' own codes finds 27 fares from Liverpool Lime Street to Manchester. With clusters and groups there are 192, and the 105 TransPennine Express fares among them are all set at cluster level. Euston to Manchester goes from 180 to 1,302.

Two things the feed does not make obvious

Advance fares are a ladder

DG0 to DG9, V2A to V2Z, USA to USZ and NAY to NMY are not different products. They are the rungs of an operator's yield-managed Advance ladder, all described as ADVANCE. There is no single Advance price; what a passenger pays depends on how far ahead they book and what is left.

median_advance_fare() takes the median across the published ladder. It only counts standard class retail fares described exactly as ADVANCE, so first class (ADVANCE 1ST) and standard premium (ADVANCE STDPREM) are left out:

median_advance_fare(table, "LIV", "MAN")  # 7.40
median_advance_fare(table, "LDS", "YRK")  # 9.70

It is a stand-in for the expected price in revenue work, not a quoted price. median_fare() is broader. It counts each ordinary adult product once (the Advance rungs, Anytime, Off-Peak and Super Off-Peak), singles at face value and returns at half, and leaves out seasons, first class and placeholders:

median_fare(table, "LIV", "MAN")  # 9.475
median_fare(table, "EUS", "MAN")  # 68.60

Many "fares" are not prices

The feed holds far more than a passenger can buy. Negotiated products (Group, Tour Operator, School Group, Special Events, operator complimentary travel) have no advertised price, so they are published at a round placeholder (£999.00, £999.99 or £9,998.00) on every route in the country. Wholesale and settlement products (Inclusive Tour, staff, child concession) carry a token price of a few pence with no link to distance.

Both kinds are flagged in a non_retail_fare column. Nothing is dropped, so you can decide what to keep:

from rsp_fares_feed import retail_only

retail_only(lookup_pair(table, "LIV", "MAN"))

The CLI hides them by default and says how many it hid. Between London Euston and Manchester, 73 of the 1,302 published fares are not prices anyone can buy:

$ rsp-fares-feed lookup EUS MAN -d fares
note: 73 of 1302 fare(s) are non-retail placeholders (group, tour operator, settlement
tokens) and are hidden; pass --include-non-retail to show them.

Both patterns were checked against the full national feed. The thresholds are named constants in table.py if you want to change them.

Limitations

  • There are no dated prices and no Advance availability. The feed holds the permanent fares. What is on sale for a given day is in each operator's own retail system, so nothing here can price an exact journey on an exact date.
  • A folder cleaned with version 0.1 has no clusters file. It still loads, with a warning, but finds only fares set for single stations. Run clean again to fix it.
  • Routeing is not interpreted. route_code is reported as published; whether a ticket is valid on a particular train is a question for the National Routeing Guide.
  • Restriction codes are reported but not explained. The .RST file that describes them is not parsed.
  • Some ticket types are for testing (NAP, "FOR TEST USE ON", above) and are not flagged. Check the description if a price looks odd.
  • A flow marked R is reversible, and lookup_pair relabels it so it reads in the direction you asked for. A flow marked S has no fare the other way, so the reverse lookup is empty.
  • The feed is republished roughly three times a year, so download it again rather than keep an old copy.

Python API

Name
fetch_feed(dest) log in to NRDP, download the feed and extract it
clean_feed(raw, out) parse .FFL, .LOC, .TTY and .FSC into four CSVs
build_fares_table(dir) load them into a FaresTable
lookup_pair(table, o, d) fares for a pair, cheapest first, with cluster, group and reversible fares
median_fare(table, o, d) median adult standard fare per journey, in pounds
median_advance_fare(table, o, d) median standard class Advance fare, in pounds
parse_clusters(raw) every (cluster or group, member) pair in the feed
flag_non_retail(flow) a boolean Series marking placeholder and settlement prices
retail_only(fares) drop the flagged rows

Every error is a subclass of FaresFeedError.

Development

git clone https://github.com/rosedillon/rsp-fares-feed
cd rsp-fares-feed
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
ruff check . && ruff format --check . && mypy src

The tests build synthetic feed files at the same character positions as the real ones, and use a scripted fake in place of urlopen for the download, so login, token handling and extraction are tested with no network or credentials. No licensed data is committed.

Licence

GPL-3.0. See LICENSE.

Not affiliated with or endorsed by the Rail Delivery Group, Rail Settlement Plan or National Rail.

Metadata

Release files for rsp-fares-feed 0.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 rsp-fares-feed 0.2.0
File Size Uploaded Provenance Actions
rsp_fares_feed-0.2.0.tar.gz 37.1 kB With provenance Details for rsp_fares_feed-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for rsp-fares-feed 0.2.0
File Interpreter ABI Platform Actions
rsp_fares_feed-0.2.0-py3-none-any.whl Python 3 none any Details for rsp_fares_feed-0.2.0-py3-none-any.whl

Total release size: 68.5 kB

Release files / rsp_fares_feed-0.2.0.tar.gz

Download URL rsp_fares_feed-0.2.0.tar.gz
Size 37.1 kB
Tags Source
SHA-256 checksum
How to use checksums
00770f1a8afde6da4b0bf2bcbb89c4639176159e3fbec428cb1f70d447d6992c
BLAKE2b-256 checksum
How to use checksums
1f053ea0c01d9047f8912aefe38d1936c4535854ff2775b903e7d808d52c709f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / rsp_fares_feed-0.2.0-py3-none-any.whl

Download URL rsp_fares_feed-0.2.0-py3-none-any.whl
Size 31.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bfce480360e36771cab389439bb430aeb886b51f10cddb94201814196dfaab02
BLAKE2b-256 checksum
How to use checksums
921a994b14d48e053b30033f563f0b72c30b977e8de6b44c9daec677b5a24248
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for rsp-fares-feed 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for rsp_fares_feed-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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