Skip to main content

size_badge version_badge download_badge GitHub Repo stars GitHub Issues or Pull Requests GitHub License

Made for Home Assistant

Sponsor me Discord

pytrafikverket

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

Development and testing done with 3.13

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"

Download files

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

Source Distribution

pytrafikverket-2.0.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

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

pytrafikverket-2.0.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytrafikverket-2.0.0.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.2 CPython/3.12.3 Linux/6.17.0-1022-azure

File hashes

Hashes for pytrafikverket-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8921d1a90e2ca5fc971dea58549e9d702e5f1fb030d9894a1409e2a7757c80d4
MD5 d9b8b3ad29ca27860623e5c705f351f5
BLAKE2b-256 a6257f5752bdfc4aebf90b6610173df012140517a3172f66238d04211c2a6700

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytrafikverket-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.2 CPython/3.12.3 Linux/6.17.0-1022-azure

File hashes

Hashes for pytrafikverket-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 944f2f818c179935180a99e14c6c582107ae54b07351637c3f8ce2c8745bebf4
MD5 1af20adf9bcbb602c4e9e98b26da298e
BLAKE2b-256 b53276b718f069d3062a20bb62f620a4b74af90081521e2ca8bf44b85c31892c

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.3.10

2 files

0.3.9.2

2 files

0.3.9.1

2 files

0.3.9

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0.1

2 files

0.2

2 files

0.1.6.2

1 file

0.1.6.1

1 file

0.1.5.9

2 files

0.1.5.8

2 files

0.1.5.7

2 files

0.1.5.6

2 files

0.1.5.5

2 files

0.1.5.4

2 files

0.1.5.3

2 files

0.1.5.2

2 files

0.1.5.1

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1

2 files

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