Skip to main content

Retrieve 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

trafikverket_cli -key <api_key> -method search-for-station -station "Kristianstad"
trafikverket_cli -key <api_key> -method get-next-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg"
trafikverket_cli -key <api_key> -method get-next-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg" -train-product "SJ Regional"
trafikverket_cli -key <api_key> -method get-train-stop -from-station "Kristianstad C" -to-station "Sölvesborg" -date-time "2017-05-19T16:38:00"
trafikverket_cli -key <api_key> -method get-weather -station "Nöbbele"
trafikverket_cli -key <api_key> -method search-for-ferry-route -route "sund"
trafikverket_cli -key <api_key> -method get-ferry-route -route "Adelsöleden"
trafikverket_cli -key <api_key> -method get-next-ferry-stop -from-harbor "Ekerö"
trafikverket_cli -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-1.0.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

pytrafikverket-1.0.0-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytrafikverket-1.0.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure

File hashes

Hashes for pytrafikverket-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aaf25b004e42d7d452839a7cdb7b0227f7562070520f8909af0fe9f0f1761e42
MD5 45137d9a66b8fe1624f5a680c38c6d3b
BLAKE2b-256 7f4ea59488649ccc7c5a4125cf73bb158cc9dbc3e75eac7e9636b0548dd0fe26

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytrafikverket-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.5.0-1022-azure

File hashes

Hashes for pytrafikverket-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7f4c8ce7b801f8133ba0388a15c08597ddab5fb47a2ce85ededbae93d692189e
MD5 9f0e55f7b6356f632abedaff3c69fee2
BLAKE2b-256 fece43352f31af62b7af58d837500b6c03f08865d8ed46d753eda9299257367c

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