Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 2.28 KB

get_started.rst

File metadata and controls

56 lines (38 loc) · 2.28 KB

Get started

Terminology

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

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

Installation

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 <pyhafas.client.HafasClient> and the DBProfile <pyhafas.profile.db.DBProfile> of pyHaFAS and creates the HafasClient <pyhafas.client.HafasClient> with the profileG. The DBProfile <pyhafas.profile.db.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())

print(client.locations("Berlin"))

print(client.departures(
    station='8011160',
    date=datetime.datetime.now(),
    max_journeys=5
))

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.