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"

Metadata

Release files for pytrafikverket 2.0.0

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 2.0.0
File Size Uploaded
pytrafikverket-2.0.0.tar.gz 19.6 kB Details

Built distribution (wheel)

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

Total release size: 39.1 kB

Release files / pytrafikverket-2.0.0.tar.gz

Download URL pytrafikverket-2.0.0.tar.gz
Size 19.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8921d1a90e2ca5fc971dea58549e9d702e5f1fb030d9894a1409e2a7757c80d4
BLAKE2b-256 checksum
How to use checksums
a6257f5752bdfc4aebf90b6610173df012140517a3172f66238d04211c2a6700
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.2 CPython/3.12.3 Linux/6.17.0-1022-azure

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

Download URL pytrafikverket-2.0.0-py3-none-any.whl
Size 19.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
944f2f818c179935180a99e14c6c582107ae54b07351637c3f8ce2c8745bebf4
BLAKE2b-256 checksum
How to use checksums
b53276b718f069d3062a20bb62f620a4b74af90081521e2ca8bf44b85c31892c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.2 CPython/3.12.3 Linux/6.17.0-1022-azure
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