Get Public Transport Timetables

About two years ago, I shared an article about a project where I query and process results from the Google Transit API in a way that provides a simple overview for public transport connections between two places. Since I ended up using it rather frequently, I decided to turn it into a proper Python package, called gptt, available on GitHub and PyPI.


gptt is primarily intended to be used as a command line tool, although its core functions can be used in any Python program. Using the default template (which can be customized or entirely replaced), it generates detailed timetables like this one:

Connections between Budapest and Balatonhenye in Hungary on August 19, 2018 as generated by the original script.

Why not just use Google’s transit results as aviable on Google Maps? As I explained in the previous post: The “Schedule Explorer” interface […] is somewhat unintuitive (as you scroll, the displayed length of the trip might change) and buggy (sometimes when I click on a transit option to see the details I am presented with the details of a different option). It is also not possible to see all options for a day.

Just like in my initial Jupyter notebook, the default template contains the following information:

  • each leg of the trip
  • depature and arrival localities, stations, and times
  • vehicle (line) name and type (bus, train, etc) as well as destination (to know what to look for at the station)
  • overall departure and arrival time and trip duration
Display showing trains departing from Déli Railway Station in Budapest, Hungary on October 8, 2020. Photo courtesy of a friend — all rights reserved.


After installing the package (e.g. with pip install gptt), a command line interface is available for use. Detailed instructions can be found in the readme, but the overall idea is relatively simple: you can query a day's connections between two points using the following command:

gptt -f "London" -t "Manchester" -d "2020-08-19" -k "ab4ab2fa-74c9-4af1-a250-9efe735c80fb"

The parameter indicated by -k is a Google API key, which you need to create yourself. You need a Google Cloud Platform project with the Directions and Time Zone API enabled. The documentations for these APIs ( Directions, Time Zone) will help you get started.

I encourage you to explore the documentation of the package, where all the possible parameters and options are described in detail. If you have any ideas how to further improve this project, don’t hesitate to reach out to me — or, if you are a programmer, feel free to submit a pull request to the repo.

Originally published at on May 24, 2020.

Transportation Economist by training, currently working as a Data Scientist at Map and geo data enthusiast. Avid hiker. Personal website:

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store