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: profile
G
Term | Meaning |
---|---|
profile | Customization for each HaFAS deployment - Contains the endpoint, tokens and possible changes for the deployment |
FPTF | Abbreviation for Friendly Public Transport Format - Used as the basis for returned data |
Station Board | Generalization for arrivals <pyhafas.client.HafasClient.arrivals> and departures <pyhafas.client.HafasClient.departures> requests |
You only need to install the pyhafas package, for example using pip:
$ pip install pyhafas
Below is a sample code for easy usage. It has multiple parts:
- It imports the
HafasClient <pyhafas.client.HafasClient>
and theDBProfile <pyhafas.profile.db.DBProfile>
of pyHaFAS and creates theHafasClient <pyhafas.client.HafasClient>
with theprofile
G. TheDBProfile <pyhafas.profile.db.DBProfile>
is theprofile
G belonging to the HaFAS deployment of Deutsche Bahn. - It searches for locations (stations) with the term "Berlin" and prints the result
- 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())
print(client.locations("Berlin"))
print(client.departures(
station='8011160',
date=datetime.datetime.now(),
max_journeys=5
))
For a good start with pyHaFAS you should go on reading the documentation. Especially the pages /usage/examples
and profiles
are a good start.