Python, FastAPI, React, Vite

Rail Barometer

Context

Rail Barometer is a real-time departure board for Belgian railway stations. This project let me practise a complete data pipeline: collecting information through the official iRail API, cleaning and transforming it in Python, then integrating it into a Vite / React front-end.

Challenge

The raw API responses are large and hard to read: times are given as Unix timestamps, delays in seconds, and train details are scattered across several nested objects. The challenge was to build an intermediate layer that only sends clean, typed, ready-to-display data to the front-end.

Data collection through the official API

A FastAPI back-end queries the liveboard endpoint of the official iRail API asynchronously with httpx. Each station is exposed through a dedicated /stations/{station} route, and network errors or empty responses are caught to return an explicit HTTP error rather than corrupted data.

Cleaning and transformation

  • Time calculation: the Unix timestamps of departures and of the last update are converted into readable HH:MM times.
  • Delay calculation: delays provided in seconds are converted to minutes, ready to be displayed next to the departure time.
  • Restructuring: only the useful information is kept (destination, train ID and type, platform, time, delay) and grouped into a clear structure.
  • DTO validation: Pydantic models (StationDTO, DepartureDTO, VehicleDTO) guarantee the shape of the data returned by the API.

Front-end integration with Vite / React

  • Shared contract: the Python DTOs are mirrored as TypeScript types, keeping the back-end and the interface consistent.
  • Always fresh data: TanStack Query handles caching, automatic refresh every 60 seconds, request cancellation and retries on failure.
  • Interface: a sidebar switches between stations, and three tabs show the departure preview, the returned JSON and the DTO structure. Everything is styled with Tailwind CSS.
Back
Contact

Let's take the time to talk

  • Available
  • Charleroi, Belgium
  • AI-Augmented