Skip to main content

Retreive values from public API at the Swedish Transport Administration (Trafikverket).

Project description

pytrafikverket

python module for communicating with the swedish trafikverket api

Development and testing done with 3.11

Code example

from pytrafikverket import TrafikverketTrain, StationInfo
import aiohttp
import asyncio
from datetime import datetime

async def main(loop):
	async with aiohttp.ClientSession(loop=loop) as session:
		train_api = TrafikverketTrain(session, "api_key_here")
		stations = await train_api.async_search_train_stations("kristianstad")
		for station in stations:
			print(station.name + " " + station.signature)

		from_station = await train_api.async_get_train_station("Sölvesborg")
		to_station = await train_api.async_get_train_station("Kristianstad C")
		product_description = "SJ Regional" # Optional search field
		print("from_station_signature: " + from_station.signature)
		print("to_station_signature:   " + to_station.signature)
		train_stop = await train_api.async_get_train_stop(from_station, to_station, datetime(2022, 4, 11, 12, 57), product_description);
		print(train_stop.get_state())

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))

CLI example

$ py pytrafikverket.py -key <api_key> -method search-for-station -station "Kristianstad"
$ py pytrafikverket.py -key <api_key> -method get-next-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg"
$ py pytrafikverket.py -key <api_key> -method get-next-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg" -train-product "SJ Regional"
$ py pytrafikverket.py -key <api_key> -method get-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg" -date-time "2017-05-19T16:38:00"
$ py pytrafikverket.py -key <api_key> -method get-weather -station "Nöbbele"
$ py pytrafikverket.py -key <api_key> -method search-for-ferry-route -route "sund"
$ py pytrafikverket.py -key <api_key> -method get-ferry-route -route "Adelsöleden"
$ py pytrafikverket.py -key <api_key> -method get-next-ferry-stop -from-harbor "Ekerö"
$ py pytrafikverket.py -key <api_key> -method get-next-ferry-stop -from-harbor "Furusund" -date-time "2019-12-24T00:00:00"

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

pytrafikverket-0.3.8.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

pytrafikverket-0.3.8-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file pytrafikverket-0.3.8.tar.gz.

File metadata

  • Download URL: pytrafikverket-0.3.8.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for pytrafikverket-0.3.8.tar.gz
Algorithm Hash digest
SHA256 de9dad285bb3825f9515145757ae8c46070bd574bcc710ea30e519c3e425ff91
MD5 fab2a5a6fc0fb0b9716cbb9209d81eb9
BLAKE2b-256 26fa1a962526cad0e540a5664ec658aa07612c613c72a29cff0a939701dd3333

See more details on using hashes here.

File details

Details for the file pytrafikverket-0.3.8-py3-none-any.whl.

File metadata

File hashes

Hashes for pytrafikverket-0.3.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0bb40c9ac14a4cd531211433b2a43d471f4aff3f4b617cad1b0feac1bf27edb6
MD5 739f6d2ae0583cb2063b6b97f50511bc
BLAKE2b-256 2d1b451c13ff7aba6b08d3844a9182c676141325c31b24e8f2ae5d8cafd8781a

See more details on using hashes here.

Supported by

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