HafasClient

The HafasClient is the interface between your program and pyhafas internal code. You need it when you’re using pyHaFAS. Below you can find the API of the client.

class pyhafas.client.HafasClient(profile, ua='pyhafas', debug=False)[source]

The interface between the user’s program and pyHaFAS internal code.

Parameters
  • profile (ProfileInterface) – Profile to be used

  • ua (str) – (optional, not recommended to change) The user-agent which will be sent to HaFAS. By default “pyhafas”, but is often overwritten by profile to emulate the app.

  • debug (bool) – (optional) Whether debug mode should be enabled. Defaults to False.

arrivals(station, date, max_trips=- 1, duration=- 1, products={}, direction=None)[source]

Returns arriving trips at the specified station

To get detailed information on the trip use the trip method with the id

Parameters
  • station (Union[Station, str]) – FPTF Station object or ID of station

  • date (datetime) – Date and Time when to search

  • max_trips (int) – (optional) Maximum number of trips to be returned. Default is “whatever HaFAS wants”

  • duration (int) – (optional) Minutes after date in which is search is made. Default is “whatever HaFAS wants”

  • products (Dict[str, bool]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.

  • direction (Union[Station, str, None]) – (optional) Direction (end) station of the vehicle. Default is any direction station is allowed

Return type

List[StationBoardLeg]

Returns

List of FPTF StationBoardLeg objects with arriving trips

departures(station, date, max_trips=- 1, duration=- 1, products={}, direction=None)[source]

Returns departing trips at the specified station

To get detailed information on the trip use the trip method with the id

Parameters
  • station (Union[Station, str]) – FPTF Station object or ID of station

  • date (datetime) – Date and Time when to search

  • max_trips (int) – (optional) Maximum number of trips to be returned. Default is “whatever HaFAS wants”

  • duration (int) – (optional) Minutes after date in which is search is made. Default is “whatever HaFAS wants”

  • products (Dict[str, bool]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.

  • direction (Union[Station, str, None]) – (optional) Direction (end) station of the vehicle. Default is any direction station is allowed

Return type

List[StationBoardLeg]

Returns

List of FPTF StationBoardLeg objects with departing trips

journey(journey)[source]

Returns information about a specific journey by its ID

Useful if you want to refresh the data of the trip, e.g. the real-time data.

Parameters

journey (Union[Journey, str]) – FPTF Journey object or journey ID

Return type

Journey

Returns

FPTF Journey object with current/updated information

journeys(origin, destination, date, via=[], min_change_time=0, max_changes=- 1, products={}, max_journeys=- 1)[source]

Returns possible journeys between two destinations

Possible journeys between two destinations are calculated by HaFAS and returned. It’s also possible to add multiple via stations.

Parameters
  • origin (Union[Station, str]) – FPTF Station object or ID of origin/starting station

  • destination (Union[Station, str]) – FPTF Station object or ID of destination/ending station

  • date (datetime) – Date and Time when to search

  • via (List[Union[Station, str]]) – (optional) List of via stations. The route is calculated via all of these stations in the order of the list. The stations have to be a FPTF Station object or the ID of the station. The default is no via stations.

  • min_change_time (int) – (optional) Minimum transfer/change time at each station. Default is the default that HaFAS specifies internal.

  • max_changes (int) – (optional) Maximum number of changes. Default is unlimited.

  • products (Dict[str, bool]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.

  • max_journeys (int) – (optional) Maximum number of returned journeys. Default is the default that HaFAS specifies internal.

Return type

List[Journey]

Returns

List of FPTF Journey objects

journeys_from_leg(origin, destination, via=[], min_change_time=0, max_changes=- 1, products={})[source]

Returns possible journeys from a leg to a destination

Possible journeys between two destinations are calculated by HaFAS and returned. It’s also possible to add multiple via stations.

Parameters
  • origin (Leg) – FPTF Leg object from where to search

  • destination (Union[Station, str]) – FPTF Station object or ID of destination/ending station

  • via (List[Union[Station, str]]) – (optional) List of via stations. The route is calculated via all of these stations in the order of the list. The stations have to be a FPTF Station object or the ID of the station. The default is no via stations.

  • min_change_time (int) – (optional) Minimum transfer/change time at each station. Default is the default that HaFAS specifies internal.

  • max_changes (int) – (optional) Maximum number of changes. Default is unlimited.

  • products (Dict[str, bool]) – (optional) Dict of product name(s) and whether it should be enabled or not. Modifies the default products specified in the profile.

Return type

List[Journey]

Returns

List of FPTF Journey objects

locations(term, rtype='S')[source]

Returns stations (and addresses) that are searched with the provided term

The further forward the station is in the list, the higher the similarity to the search term.

Parameters
  • term (str) – Search term

  • rtype (str) – Result types. One of [‘S’ for stations only, ‘ALL’ for addresses and stations]

Return type

List[Station]

Returns

List of FPTF Station objects

nearby(location)[source]

Not implemented yet.

radar(north, west, south, east)[source]

Not implemented yet.

stop(stop)[source]

Not implemented yet.

trip(id)[source]

Returns detailed information about a trip based on its ID

Parameters

id (str) – ID of the trip

Return type

Leg

Returns

Detailed trip information as FPTF Leg object