Skip to main content

An unofficial python wrapper for the SBB api.

Project description

pySBB

This is an unofficial python wrapper for the SBB API. SBB stands for the "Schweizerische Bundes Bahnen" (Swiss Federal Transport).

Installation

pip3 install pySBB

Usage

This package lets you access the SBB api easily. Here is how to use it:

Get Connections

It is very simple to get connections between two stations:

import pySBB

connections = pySBB.get_connections("Zürich", "Bern")
for c in connections:
	print(c)

Example Output:

Zürich HB (18:32, Plat. 32) -> Bern (19:28, Plat. 32) | 56min
Zürich HB (19:02, Plat. 31) -> Bern (19:58, Plat. 31) | 56min
Zürich HB (19:32, Plat. 32) -> Bern (20:28, Plat. 32) | 56min
Zürich HB (20:02, Plat. 31) -> Bern (20:58, Plat. 31) | 56min

Further parameters (see connections) for more info:

  • via: Specifies up to five via locations.
  • date: Date of the connection, in the format YYYY-MM-DD
  • time: Time of the connection, in the format hh:mm
  • isArrivalTime: Defaults to False, if set to True the passed date and time is the arrival time
  • transportations: Transportation means; one or more of train, tram, ship, bus, cableway
  • limit: 1 - 16. Specifies the number of connections to return. If several connections depart at the same time they are counted as 1.
  • page: 0 - 3. Allows pagination of connections. Zero-based, so first page is 0, second is 1, third is 2 and so on.
  • direct: defaults to False, if set to True only direct connections are allowed
  • sleeper: defaults to False, if set to True only direct connections are allowed
  • couchette: defaults to False, if set to True only night trains containing couchettes are allowed, implies direct=True
  • bike: defaults to False, if set to True only trains allowing the transport of bicycles are allowed
  • accessibility: Possible values are independent_boarding, assisted_boarding, and advanced_notice

Get Locations

The api allows you to find locations such as train stations, addresses and other point of interests (eg. Clock Tower or China Garden)

import pySBB

locations = pySBB.get_locations(query="Lidostrasse 5 Luzern")
for l in locations:
    print(l)

Example Output:

Luzern, Lidostr. 5 
Verkehrshaus der Schweiz, Luzern, Lidostr. 5
Restaurant Piccard im Verkehrshaus der Schweiz, Luzern, Lidostr. 5
...

Further parameters (see locations for more info:

  • query: Specifies the location name to search for
  • x: Latitude
  • y: Longitude
  • type: Only with query parameter. Specifies the location type, possible types are:
    • all (default): Looks up for all types of locations
    • station: Looks up for stations (eg. train station, bus station)
    • poi: Looks up for points of interest (eg. Clock tower, China garden)
    • address: Looks up for an address (eg. Zurich Bahnhofstrasse 33)

Get Stationboards

Stationboards are the big blue boards that can be seen at trainstations. These are also available via the api.

import pySBB

entries = pySBB.get_stationboard("Lugano")
for e in entries:
    print(e)

Example Output:

Lugano (18:51, Plat. 2) -> Chiasso
Lugano (18:55, Plat. 4) -> Bellinzona
Lugano (19:05, Plat. 2) -> Chiasso
Lugano (19:22, Plat. 2) -> Monza
Lugano (19:25, Plat. 4) -> Bellinzona
...

Further parameters (see stationboard) for more info:

  • id: The id of the station whose stationboard should be returned. Overwrites to the station parameter.
  • limit: Number of departing connections to return.
  • transportations: Transportation means; one or more of train, tram, ship, bus, cableway
  • date: Date of departing connections, in the format YYYY-MM-DD
  • time: Time of departing connections, in the format hh:mm
  • type: departure (default) or arrival

Objects

This is a descripition of all objects used by this api.

Connection

A connection represents a possible journey between two locations.

Parameters:

Name Type Description
start Stop The starting point of the journey
end Stop The end point of the journey
duration Duration How long the journey takes

Functions:

Name Return Type Description
str str Returns a string representation of the Connection.

Stop

A stop represents an arrival or a departure point (in time and space) of a connection.

Parameters:

Name Type Description
station Location A location object showing this line's stop at the requested station
arrival Time The arrival time to the checkpoint
departure Time The departure time from the checkpoint
delay int The delay of this connection
platform str The arrival/departure platform

Functions:

Name Return Type Description
str str Returns a string representation of the Stop.

Location

Can be any location, station address or point of iterest.

Parameters:

Name Type Description
id int The id of the location
name str The name of the location
score str The accuracy of the result
distance int If search has been with coordinates, distance to original point in meters
coordinates Coordinates The location coordinates

Functions:

Name Return Type Description
str str Returns a string representation of the Location.

Duration

A duration object holds the duration it takes to complete a journey

Parameters:

Name Type Description
days int The number of days
hours int The number of hours
minutes int The number of minutes
seconds int The number of seconds

Functions:

Name Return Type Description
str str Returns a string representation of the Duration.

Time

A time object holds the time for some event such as arrival at a checkpoint. Notice that there is no

Parameters:

Name Type Description
year int The year of this event
month int The month of this event
day int The day of this event
hour int The hour of this event
minute int The minute of this event

Functions:

Name Return Type Description
str str Returns a string representation of the Time.

Coordinates

Coordinates describe the location of any geographical point used by this package.

Parameters:

Name Type Description
x int The latitude
y int The longitude

Functions:

Name Return Type Description
str str Returns a string representation of the Coordinates.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pySBB-1.0.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pySBB-1.0.0-py3.6.egg (13.2 kB view details)

Uploaded Egg

pySBB-1.0.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pySBB-1.0.0.tar.gz.

File metadata

  • Download URL: pySBB-1.0.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for pySBB-1.0.0.tar.gz
Algorithm Hash digest
SHA256 17459671d2a1a88d070ac6bb6e795aeeb486bbf2a166ef4d857ae8aba9c05d32
MD5 db760f91c7739bd032a0d0e9d674da1b
BLAKE2b-256 896ca47082f80056a759730224d0d65d5f378f76b70ddf827d61d7e1615faee3

See more details on using hashes here.

File details

Details for the file pySBB-1.0.0-py3.6.egg.

File metadata

  • Download URL: pySBB-1.0.0-py3.6.egg
  • Upload date:
  • Size: 13.2 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.20.0 setuptools/41.0.1 requests-toolbelt/0.8.0 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for pySBB-1.0.0-py3.6.egg
Algorithm Hash digest
SHA256 53b8d12c3eae09199532db39eb16fc0f6306b98121dd9970d7ee44e45db9b393
MD5 fb84985c28a6c9020bdb14cb74f00aba
BLAKE2b-256 242ad9d99f38cf9ee4ec0e88db86861200848af695b4bcc6ad2b223b74f522ea

See more details on using hashes here.

File details

Details for the file pySBB-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pySBB-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.7

File hashes

Hashes for pySBB-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9ddd66c9e7ceb8deec4cf704d49e10016346ac3950f6b96a0c956fd360ef6b65
MD5 b6a537f862c9237ce67bab1d0efbc51d
BLAKE2b-256 72366c86b97fc2cde17934a6d44aed8782e70c36851a33aa74d5f39330b59918

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page