skillfed

pytrafikverket

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

pytrafikverket v1.1.1 73.5K downloads/30d#14,995 on PyPI26
Permissive license MIT Active released

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 pytrafikverket

uv

uv add pytrafikverket

poetry

poetry add pytrafikverket

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishProgramming Language :: Python :: 3Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Software Development :: Libraries :: Python Modules

Tags

swedish trafikverket api clienttrain station lookup pythonasync swedish transport apiferry route querytrafikverket python wrapperswedish railway datatransport administration api
async-http-clientswedish-transportpublic-api-wrapper

More Python Modules packages