Name | trafiklab-sl JSON |
Version |
2.1.1
JSON |
| download |
home_page | None |
Summary | Storstockholms Lokaltrafik (SL) data via Trafiklab API |
upload_time | 2025-07-24 18:35:25 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.11.0 |
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.
|
keywords |
sl
storstockholms lokaltrafik
trafiklab
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Trafiklab-Sl
[](https://pypi.org/project/trafiklab-sl)
[](https://github.com/NecroKote/trafiklab-sl)
[](https://github.com/NecroKote/trafiklab-sl/actions/workflows/test.yml)
[](https://github.com/NecroKote/trafiklab-sl/blob/main/LICENSE.txt)
A data model describing 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/our-apis/sl/deviations/)
- [SL Transport API](https://www.trafiklab.se/api/our-apis/sl/transport/)
- "Departures from Site"
- "Sites"
- [SL Journey-planner v2 API](https://www.trafiklab.se/api/our-apis/sl/journey-planner-2/)
- "Stop lookup"
- "Journey Planner"
## 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.clients.journey import JourneyPlannerClient, SearchLeg
from tsl.models.common import TransportMode
from tsl.utils import global_id_to_site_id
from tsl.tools.journey import SimpleJourneyInterpreter, leg_display_str
async def main():
async with aiohttp.ClientSession() as session:
# perform stop lookup to get the site id for Stockholm Central
lookup_client = StopLookupClient(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 = global_id_to_site_id(central_station['id'])
# get upcoming train departures
client = TransportClient(session)
reponse = await client.get_site_departures(transport_api_siteid, transport=TransportMode.TRAIN)
# get step by step journey from Stockholm Central to a specific location
route_client = JourneyPlannerClient(session)
params = route_client.build_request_params(
origin=SearchLeg.from_stop_finder(central_station),
destination=SearchLeg.from_coordinates("59.274695", "18.033901"),
calc_number_of_trips=1
)
ways_to_get_there = await route_client.search_trip(params)
# use `SimpleJourneyInterpreter` to interpret the journey data in a human-readable way
print(f"Upcoming trains at {central_station['disassembledName']}:")
for departure in sorted(reponse["departures"], key=lambda d: d.get("expected", "")):
print(
f"[{departure['line'].get('designation')}] platform {departure['stop_point'].get('designation')}"
f" to {departure.get('destination')} ({departure['display']})"
)
print(f"\nNumber of ways to get from Stockholm Central to 59.274695, 18.033901 - {len(ways_to_get_there)}")
interpreter = SimpleJourneyInterpreter(ways_to_get_there[0])
print("Itinerary of the first way:")
for leg in interpreter.get_itinerary():
print(" - " + leg_display_str(leg))
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.11.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/17/4d/9bc8a36454bd5282645d9b1e9f946406f29c9a4e1b81b2892f62de8eaaf0/trafiklab_sl-2.1.1.tar.gz",
"platform": null,
"description": "# Trafiklab-Sl\n\n[](https://pypi.org/project/trafiklab-sl)\n[](https://github.com/NecroKote/trafiklab-sl)\n[](https://github.com/NecroKote/trafiklab-sl/actions/workflows/test.yml)\n[](https://github.com/NecroKote/trafiklab-sl/blob/main/LICENSE.txt)\n\nA data model describing 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/our-apis/sl/deviations/)\n- [SL Transport API](https://www.trafiklab.se/api/our-apis/sl/transport/)\n - \"Departures from Site\"\n - \"Sites\"\n- [SL Journey-planner v2 API](https://www.trafiklab.se/api/our-apis/sl/journey-planner-2/)\n - \"Stop lookup\"\n - \"Journey Planner\"\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.clients.journey import JourneyPlannerClient, SearchLeg\nfrom tsl.models.common import TransportMode\nfrom tsl.utils import global_id_to_site_id\nfrom tsl.tools.journey import SimpleJourneyInterpreter, leg_display_str\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(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 = global_id_to_site_id(central_station['id'])\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 # get step by step journey from Stockholm Central to a specific location\n route_client = JourneyPlannerClient(session)\n params = route_client.build_request_params(\n origin=SearchLeg.from_stop_finder(central_station),\n destination=SearchLeg.from_coordinates(\"59.274695\", \"18.033901\"),\n calc_number_of_trips=1\n )\n ways_to_get_there = await route_client.search_trip(params)\n # use `SimpleJourneyInterpreter` to interpret the journey data in a human-readable way\n\n print(f\"Upcoming trains at {central_station['disassembledName']}:\")\n for departure in sorted(reponse[\"departures\"], key=lambda d: d.get(\"expected\", \"\")):\n print(\n f\"[{departure['line'].get('designation')}] platform {departure['stop_point'].get('designation')}\"\n f\" to {departure.get('destination')} ({departure['display']})\"\n )\n\n print(f\"\\nNumber of ways to get from Stockholm Central to 59.274695, 18.033901 - {len(ways_to_get_there)}\")\n interpreter = SimpleJourneyInterpreter(ways_to_get_there[0])\n\n print(\"Itinerary of the first way:\")\n for leg in interpreter.get_itinerary():\n print(\" - \" + leg_display_str(leg))\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.\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "Storstockholms Lokaltrafik (SL) data via Trafiklab API",
"version": "2.1.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": null,
"digests": {
"blake2b_256": "c9f216832f8e0c5847ead296cb45e32c8f34879492b51be72e81657c58ced49b",
"md5": "a21ac0adf90e4c42a94dcf6c1a8f3304",
"sha256": "89bf7f88024b04556468de53d756a1d60e96e8e3ff1944eb4efd497e83b5a280"
},
"downloads": -1,
"filename": "trafiklab_sl-2.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a21ac0adf90e4c42a94dcf6c1a8f3304",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11.0",
"size": 16266,
"upload_time": "2025-07-24T18:35:23",
"upload_time_iso_8601": "2025-07-24T18:35:23.987192Z",
"url": "https://files.pythonhosted.org/packages/c9/f2/16832f8e0c5847ead296cb45e32c8f34879492b51be72e81657c58ced49b/trafiklab_sl-2.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "174d9bc8a36454bd5282645d9b1e9f946406f29c9a4e1b81b2892f62de8eaaf0",
"md5": "b9a1bb9537cc97eb76459624973f4062",
"sha256": "62cc7c1d82fb5d15d3175abe33cad28d551a22288d836607c9c3c3af8154082a"
},
"downloads": -1,
"filename": "trafiklab_sl-2.1.1.tar.gz",
"has_sig": false,
"md5_digest": "b9a1bb9537cc97eb76459624973f4062",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11.0",
"size": 12563,
"upload_time": "2025-07-24T18:35:25",
"upload_time_iso_8601": "2025-07-24T18:35:25.523292Z",
"url": "https://files.pythonhosted.org/packages/17/4d/9bc8a36454bd5282645d9b1e9f946406f29c9a4e1b81b2892f62de8eaaf0/trafiklab_sl-2.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-24 18:35:25",
"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"
}