pytrafikverket
Retrieve values from public API at the Swedish Transport Administration (Trafikverket).
What it is and what it does
Pytrafikverket is an async Python wrapper around the Swedish Transport Administration's (Trafikverket) public API. It provides high-level methods to search and retrieve train station information, query train schedules between stations, look up ferry routes and schedules, and fetch weather data at transport locations. The library uses aiohttp for non-blocking HTTP requests, making it suitable for integration into async applications or services that need to poll transport data without blocking.
The package includes both a programmatic API (via TrafikverketTrain and related classes) and a CLI tool for direct queries. It requires an API key from Trafikverket and Python 3.11 or later. Dependencies are lightweight: aiohttp for HTTP, lxml for XML parsing, yarl for URL handling, and aiozoneinfo for timezone support.
Use it for:
- Build a travel planner or commute app that queries real-time Swedish train schedules and station information.
- Monitor ferry route availability and schedules for Swedish waterway transport.
- Fetch weather conditions at Swedish transport hubs for operational decision-making.
- Create a CLI tool or dashboard that displays next available train or ferry departures.
- Integrate transport data into a broader Swedish logistics or mobility platform.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Async Python client for querying Sweden's Trafikverket public API to retrieve train stations, schedules, ferry routes, and weather data.
Yes, if you need to query Swedish Trafikverket data. The package is actively maintained, has no known vulnerabilities, uses a permissive MIT license, and installs with low friction. The async design and modern Python support (3.11+) make it well-suited for contemporary applications. Verify that your use case aligns with Trafikverket's API terms and that you can obtain an API key.
Install
pytrafikverket on PyPI
pip
pip install pytrafikverketuv
uv add pytrafikverketpoetry
poetry add pytrafikverketInstalling pytrafikverket
Before you install
Low friction install with a pure-Python wheel. Actively maintained as of 2026-08-12 with recent releases. Supports Python 3.11, 3.12, and 3.13.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed projects with minimal attribution requirements.
Quickstart
import asyncio
import aiohttp
from pytrafikverket import TrafikverketTrain
async def main():
async with aiohttp.ClientSession() as session:
train_api = TrafikverketTrain(session, "your_api_key")
stations = await train_api.async_search_train_stations("kristianstad")
for station in stations:
print(station.name)
asyncio.run(main())
Requires a valid Trafikverket API key; obtain one from the Swedish Transport Administration before use.
Verify before relying
- Whether the Trafikverket API key is free or requires registration/payment
- Rate limits or quotas enforced by the Trafikverket API
- Geographic scope: whether the API covers all Swedish transport or only specific regions
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.11) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — aiohttp, aiozoneinfo, lxml, yarl |
| Maintenance | actively maintained — 630 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 73,466/month — #14,995 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytrafikverket-1.1.1-py3-none-any.whl
Keywords: trafikverket, api, async, client
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
aioymapsaioymaps is an async client library for…
permissive · top 15,000 on PyPI
radiosAn async Python client for querying the Radio…
permissive · top 15,000 on PyPI
imgw-pibAn async Python wrapper for the IMGW-PIB API…
permissive · top 15,000 on PyPI
aioambientAn async Python library for querying Ambient…
permissive · top 15,000 on PyPI
ocppImplements the JSON version of the Open Charge…
permissive · top 15,000 on PyPI
PyRMVtransportQueries real-time and scheduled transport…
permissive · top 15,000 on PyPI
giosFetches real-time air quality measurements from…
permissive · top 15,000 on PyPI
pyairvisualA thin async Python wrapper for the AirVisual…
permissive · top 15,000 on PyPI
aioecowittProvides an async Python wrapper for the…
permissive · top 15,000 on PyPI
pyatmopyatmo provides a Python API to query Netatmo…
permissive · top 15,000 on PyPI