Skip to main content

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"

Metadata

Release files for pytrafikverket 0.3.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytrafikverket 0.3.10
File Size Uploaded
pytrafikverket-0.3.10.tar.gz 14.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytrafikverket 0.3.10
File Interpreter ABI Platform
pytrafikverket-0.3.10-py3-none-any.whl Python 3 none any Details

Total release size: 32.1 kB

Release files / pytrafikverket-0.3.10.tar.gz

Download URL pytrafikverket-0.3.10.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0772bdc03163eee4a0b3a06c2549c3eabd8955c1fbbbb52b6d55d44cc1aa9901
BLAKE2b-256 checksum
How to use checksums
dfadfba1119843361564907d22be8342febebff97a486451a27a248fac7b25e9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / pytrafikverket-0.3.10-py3-none-any.whl

Download URL pytrafikverket-0.3.10-py3-none-any.whl
Size 17.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42230c669c037dea1a7ccde1076b8e63a3d04bf8be0dbd874113546d1a5f17d9
BLAKE2b-256 checksum
How to use checksums
c714f825e856a509218491727a2a261d4d7acfbb3ab5a0a95110c08fc555ad2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page