Skip to main content

Storstockholms Lokaltrafik (SL) data via Trafiklab API

Project description

Trafiklab-Sl

version python version license

A data model for Storstockholms Lokaltrafik (SL) data.

Also contains an async client for fetching data from the Trafiklab API.

Installation

Install using pip install -U trafiklab-sl

Development

To install the package for development, clone the repository and run:

python -m venv .venv
source .venv/bin/activate
pip install -e '.[dev,test]'

Usage

The client is based on the aiohttp library and is async. It is used to fetch data from the Trafiklab API. The library supports two SL APIs:

More APIs will be added in the future.

Example

Here is an example of how to use the client to get upcoming train departures at Stockholm Central (site Id 1002).

import asyncio

from tsl.clients.transport import TransportClient
from tsl.models.common import TransportMode


async def main():
    client = TransportClient()
    reponse = await client.get_site_departures(1002, transport=TransportMode.TRAIN)

    print("Upcoming trains at Stockholm Central:")
    for departure in sorted(reponse.departures, key=lambda d: d.expected):
        print(
            f"[{departure.line.designation}] platform {departure.stop_point.designation}"
            f" to {departure.destination} ({departure.display})"
        )


asyncio.run(main())

Contributing

Both bug reports and pull requests are appreciated.

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

trafiklab-sl-0.2.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

trafiklab_sl-0.2.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file trafiklab-sl-0.2.0.tar.gz.

File metadata

  • Download URL: trafiklab-sl-0.2.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for trafiklab-sl-0.2.0.tar.gz
Algorithm Hash digest
SHA256 50d5887b50d8eda49fc0fe66875b7430fa255735aab70f62358bea08665a079c
MD5 4a4f7456ddeb453d53219af7d3340cb5
BLAKE2b-256 38e32e8fac6191d4c4711226265069e6f6c0fc0a0f045f0fa2ab7601b4677ecd

See more details on using hashes here.

File details

Details for the file trafiklab_sl-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: trafiklab_sl-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.8

File hashes

Hashes for trafiklab_sl-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 878ca1f083288cb6c55bb5ce987e6dba244e80f4fdb10d3cf8833cb093bfa6a9
MD5 fffc211d7a62a547cea6f19f2dca25ea
BLAKE2b-256 5eaf4013b9b284dfc6ab2819ba9740de9dc03b8bcd7dea36a57f4eeb6563d9a2

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