Skip to main content

Python-JLT-BusSchedule-Scraper

Python library that scrapes the JLT site for bus schedules.

JLT (Jönköpings Länstrafik) has no public API for departures, so this library scrapes the HTML fragment used by the departure board on jlt.se, and the stop search of the travel planner that jlt.se embeds from etiscloud.net.

It is used by the JLT Bus Schedule Home Assistant integration.

Installation

pip install jlt-bus-schedule

Requires Python 3.11 or later.

Usage

import asyncio

from jlt_bus_schedule import JltApiClient


async def main() -> None:
    async with JltApiClient() as client:
        stops = await client.async_search_stops("Rådhusparken")
        stop = stops[0]
        print(f"{stop.name} ({stop.id})")

        for departure in await client.async_get_departures(stop.id, take=10):
            print(
                f"{departure.departure_time} {departure.line:>3} "
                f"{departure.destination} ({departure.time_to_departure})"
            )


asyncio.run(main())
Jönköping Rådhusparken (6001320)
13:20   3 Råslätt via Asecs-Ryhov (Avgår nu)
13:21 141 Sävsjö via Vrigstad (Avgår nu)
13:22   4 Huskvarna via Solåsen-Ryhov (Avgår om 1 min)
...

Sharing an aiohttp session

Pass an existing aiohttp.ClientSession to share it with the rest of your application, as Home Assistant integrations should. The client never closes a session it did not create.

from homeassistant.helpers.aiohttp_client import async_get_clientsession

client = JltApiClient(async_get_clientsession(hass))

Without a session the client creates its own, which is closed by await client.close() or when leaving an async with block.

Each request uses a User-Agent picked at random from a pool of common desktop browsers (USER_AGENTS). A fixed User-Agent header can be set with JltApiClient(session, user_agent="MyApp/1.0").

API

JltApiClient

Method Description
async_get_departures(stop_id, take=20, timeout=10) Upcoming departures for all lines at a stop, as a list of Departure. Departures that have already left are skipped, but JLT counts them in take, so fewer than take departures may be returned.
async_search_stops(query, timeout=10) Stops matching a name, best match first, as a list of Stop.
close() Close the session, if it was created by the client.

Both methods raise JltConnectionError on HTTP errors, connection errors and timeouts. All exceptions raised by the library inherit from JltError.

Departure

Attribute Type Example
line str "1"
destination str "Huskvarna via Centrum-Elmia"
direction str "mot Huskvarna via Centrum-Elmia"
departure datetime Timezone aware, in JLT_TIMEZONE (Europe/Stockholm)
departure_time str "11:41"
time_to_departure str "Avgår om 5 min"

Stop

Attribute Type Example
id int 6001320
name str "Jönköping Rådhusparken"

Parsers

parse_departures(html, now) and parse_stops(html) parse the HTML fragments without doing any network requests. parse_departures uses now to place the clock times on the right date, so departures after midnight end up on the next day.

Development

pip install -e ".[test]"
pytest

Tests marked live call the real jlt.se site to detect markup changes. Skip them with pytest -m "not live".

Releasing

Releases are published to PyPI by the Publish to PyPI workflow when a GitHub release is published, using trusted publishing. Bump __version__ in src/jlt_bus_schedule/const.py before creating the release.

Metadata

Release files for jlt-bus-schedule 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jlt-bus-schedule 1.1.0
File Size Uploaded Provenance Actions
jlt_bus_schedule-1.1.0.tar.gz 13.4 kB With provenance Details for jlt_bus_schedule-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for jlt-bus-schedule 1.1.0
File Interpreter ABI Platform Actions
jlt_bus_schedule-1.1.0-py3-none-any.whl Python 3 none any Details for jlt_bus_schedule-1.1.0-py3-none-any.whl

Total release size: 22.2 kB

Release files / jlt_bus_schedule-1.1.0.tar.gz

Download URL jlt_bus_schedule-1.1.0.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
99893fa0d51848cf649a88bfcf7881c398225aa6104620ce993f116045137930
BLAKE2b-256 checksum
How to use checksums
4234ef75ec1fa0c3a4325fb6fdabb87676a9450593f37f974aadb69cb7e0f47d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / jlt_bus_schedule-1.1.0-py3-none-any.whl

Download URL jlt_bus_schedule-1.1.0-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
49e4f762e45396144dd8722c92a0841234699e1365f294d069549346904eee83
BLAKE2b-256 checksum
How to use checksums
667f0dc73e4100b773f4d9a7ac7e27e0e8034482e29a10715aa612fa9752453d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for jlt-bus-schedule 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for jlt_bus_schedule-1.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page