trafiklab-sl


Nametrafiklab-sl JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryStorstockholms Lokaltrafik (SL) data via Trafiklab API
upload_time2024-12-16 16:10:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.0
licenseCopyright (c) 2024 Mikalai Kukhta and individual contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords sl storstockholms lokaltrafik trafiklab
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Trafiklab-Sl

[![version](https://img.shields.io/pypi/v/trafiklab-sl)](https://pypi.org/project/trafiklab-sl)
[![python version](https://img.shields.io/pypi/pyversions/trafiklab-sl)](https://github.com/NecroKote/trafiklab-sl)
[![test](https://github.com/NecroKote/trafiklab-sl/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/NecroKote/trafiklab-sl/actions/workflows/test.yml)
[![license](https://img.shields.io/github/license/necrokote/trafiklab-sl)](https://github.com/NecroKote/trafiklab-sl/blob/main/LICENSE.txt)

A data model for Storstockholms Lokaltrafik (SL) data.

Also contains an async client for fetching data from the [Trafiklab API](https://www.trafiklab.se/api/).

## Installation

Install using `pip install -U trafiklab-sl`

### Development

To install the package for development, clone the repository and run:
```shell
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 following SL APIs:
- [SL Deviatons API](https://www.trafiklab.se/api/trafiklab-apis/sl/deviations/)
- [SL Transport API](https://www.trafiklab.se/api/trafiklab-apis/sl/transport/)
  - "Departures from Site"
  - "Sites"
- [SL Stop lookup API](https://www.trafiklab.se/api/trafiklab-apis/sl/stop-lookup/)

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).

```python
import asyncio
import aiohttp

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


async def main():
    async with aiohttp.ClientSession() as session:

        # perform stop lookup to get the site id for Stockholm Central
        lookup_client = StopLookupClient("your 'Trafikverket öppet API' api key", session)
        stops = await lookup_client.get_stops("Stockholm Central")
        if (central_station := next(iter(stops), None)) is None:
            raise RuntimeError(r"Could not find Stockholm Central. Weird ¯\_(ツ)_/¯")

        # get the transport API site id for Stockholm Central
        transport_api_siteid = central_station.SiteId.transport_siteid

        # get upcoming train departures
        client = TransportClient(session)
        reponse = await client.get_site_departures(transport_api_siteid, transport=TransportMode.TRAIN)

    print(f"Upcoming trains at {central_station.Name}:")
    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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "trafiklab-sl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.0",
    "maintainer_email": null,
    "keywords": "SL, Storstockholms Lokaltrafik, Trafiklab",
    "author": null,
    "author_email": "Mikalai Kukhta <mikalai.kukhta@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/52/c5/f05d9c761466fff0946f4648b3c1e6dc532139a5d6ebaf9156c361e778cc/trafiklab_sl-1.0.1.tar.gz",
    "platform": null,
    "description": "# Trafiklab-Sl\n\n[![version](https://img.shields.io/pypi/v/trafiklab-sl)](https://pypi.org/project/trafiklab-sl)\n[![python version](https://img.shields.io/pypi/pyversions/trafiklab-sl)](https://github.com/NecroKote/trafiklab-sl)\n[![test](https://github.com/NecroKote/trafiklab-sl/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/NecroKote/trafiklab-sl/actions/workflows/test.yml)\n[![license](https://img.shields.io/github/license/necrokote/trafiklab-sl)](https://github.com/NecroKote/trafiklab-sl/blob/main/LICENSE.txt)\n\nA data model for Storstockholms Lokaltrafik (SL) data.\n\nAlso contains an async client for fetching data from the [Trafiklab API](https://www.trafiklab.se/api/).\n\n## Installation\n\nInstall using `pip install -U trafiklab-sl`\n\n### Development\n\nTo install the package for development, clone the repository and run:\n```shell\npython -m venv .venv\nsource .venv/bin/activate\npip install -e '.[dev,test]'\n```\n\n## Usage\n\nThe client is based on the `aiohttp` library and is async. It is used to fetch data from the Trafiklab API.\nThe library supports following SL APIs:\n- [SL Deviatons API](https://www.trafiklab.se/api/trafiklab-apis/sl/deviations/)\n- [SL Transport API](https://www.trafiklab.se/api/trafiklab-apis/sl/transport/)\n  - \"Departures from Site\"\n  - \"Sites\"\n- [SL Stop lookup API](https://www.trafiklab.se/api/trafiklab-apis/sl/stop-lookup/)\n\nMore APIs will be added in the future.\n\n## Example\n\nHere is an example of how to use the client to get upcoming train departures at Stockholm Central (site Id 1002).\n\n```python\nimport asyncio\nimport aiohttp\n\nfrom tsl.clients.stoplookup import StopLookupClient\nfrom tsl.clients.transport import TransportClient\nfrom tsl.models.common import TransportMode\n\n\nasync def main():\n    async with aiohttp.ClientSession() as session:\n\n        # perform stop lookup to get the site id for Stockholm Central\n        lookup_client = StopLookupClient(\"your 'Trafikverket \u00f6ppet API' api key\", session)\n        stops = await lookup_client.get_stops(\"Stockholm Central\")\n        if (central_station := next(iter(stops), None)) is None:\n            raise RuntimeError(r\"Could not find Stockholm Central. Weird \u00af\\_(\u30c4)_/\u00af\")\n\n        # get the transport API site id for Stockholm Central\n        transport_api_siteid = central_station.SiteId.transport_siteid\n\n        # get upcoming train departures\n        client = TransportClient(session)\n        reponse = await client.get_site_departures(transport_api_siteid, transport=TransportMode.TRAIN)\n\n    print(f\"Upcoming trains at {central_station.Name}:\")\n    for departure in sorted(reponse.departures, key=lambda d: d.expected):\n        print(\n            f\"[{departure.line.designation}] platform {departure.stop_point.designation}\"\n            f\" to {departure.destination} ({departure.display})\"\n        )\n\n\nasyncio.run(main())\n```\n\n## Contributing\n\nBoth bug reports and pull requests are appreciated.\n",
    "bugtrack_url": null,
    "license": "Copyright (c) 2024 Mikalai Kukhta and individual contributors.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Storstockholms Lokaltrafik (SL) data via Trafiklab API",
    "version": "1.0.1",
    "project_urls": {
        "Issues": "https://github.com/NecroKote/trafiklab-sl/issues",
        "Repository": "https://github.com/NecroKote/trafiklab-sl"
    },
    "split_keywords": [
        "sl",
        " storstockholms lokaltrafik",
        " trafiklab"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9dad36be4691a7a6954bc067867b852bedd233b67803917879b08db4d84561f8",
                "md5": "02e631a749143d794ae3ec3148d10f83",
                "sha256": "fcff7122e46ccdfc53c6f5f1e8199ff7adbc3187a82026a0096cb97b1c13428e"
            },
            "downloads": -1,
            "filename": "trafiklab_sl-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "02e631a749143d794ae3ec3148d10f83",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.0",
            "size": 13078,
            "upload_time": "2024-12-16T16:10:18",
            "upload_time_iso_8601": "2024-12-16T16:10:18.936551Z",
            "url": "https://files.pythonhosted.org/packages/9d/ad/36be4691a7a6954bc067867b852bedd233b67803917879b08db4d84561f8/trafiklab_sl-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "52c5f05d9c761466fff0946f4648b3c1e6dc532139a5d6ebaf9156c361e778cc",
                "md5": "54a1ebca86e0c83b01ef48e6a3535186",
                "sha256": "367cbfaff29bc930e183182a6e5cc2fc8d90c894625eaba16c25a375d00080f0"
            },
            "downloads": -1,
            "filename": "trafiklab_sl-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "54a1ebca86e0c83b01ef48e6a3535186",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0",
            "size": 10024,
            "upload_time": "2024-12-16T16:10:21",
            "upload_time_iso_8601": "2024-12-16T16:10:21.646714Z",
            "url": "https://files.pythonhosted.org/packages/52/c5/f05d9c761466fff0946f4648b3c1e6dc532139a5d6ebaf9156c361e778cc/trafiklab_sl-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-16 16:10:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NecroKote",
    "github_project": "trafiklab-sl",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "trafiklab-sl"
}
        
Elapsed time: 0.55505s