Get started


In pyHaFAS, we often use the following terms. Please read them, so you can understand the documentation and project better.

Most other pyHaFAS-specific words are defined in the Glossary. If one of these words is used in this documentation it’s marked as a link with a superscript G as follows: profileG




Customization for each HaFAS deployment - Contains the endpoint, tokens and possible changes for the deployment


Abbreviation for Friendly Public Transport Format - Used as the basis for returned data

Station Board

Generalization for arrivals and departures requests


You only need to install the pyhafas package, for example using pip:

$ pip install pyhafas

Sample Starter Code

Below is a sample code for easy usage. It has multiple parts:

  1. It imports the HafasClient and the DBProfile of pyHaFAS and creates the HafasClient with the profileG. The DBProfile is the profileG belonging to the HaFAS deployment of Deutsche Bahn.

  2. It searches for locations (stations) with the term “Berlin” and prints the result

  3. It searches for departing trains at Berlin Central Station. Every station is identified by an ID, which (in this case 8011160) can be obtained by a location-request with pyhafas.

from pyhafas import HafasClient
from pyhafas.profile import DBProfile

client = HafasClient(DBProfile())



What’s next?

For a good start with pyHaFAS you should go on reading the documentation. Especially the pages Usage Examples and Profiles are a good start.