A REPL for querying real time departure data for Stockholm's public transit system (SL) via Trafiklab APIs.
Project description
SL Transit REPL
A command-line tool for querying real time departure data from Stockholm's public transit system (SL) using Trafiklab APIs.
I made this primarily as a compliment to an xbar plugin I made to keep the next bus time for my closest stops in my menu bar. Link to plugin coming soon.
Two modes of operation:
- Interactive REPL with auto-completion and command history
- Single-query mode for scripting and automation
This is not intended as library/wrapper for programmatically accessing the Trafiklab APIs.
Features
๐ Departure Queries
- Get real-time departure information for any transit stop
- Filter by line, direction, transport mode, and forecast window
๐ Site Lookup
- Find transit stops by ID or name search
- Fuzzy name matching with diacritic support (รฅรครถ โ aao); also searches aliases and alternative names
Installation
Install from PyPI
pip install sl-transit-repl
After installation, you can use the sl-repl command from anywhere (assuming the environment where sl-transit-repl is installed is active).
Install from Source
git clone https://github.com/abonhomme/sl-transit-repl.git
cd sl-transit-repl
pip install -e .
Setup
The tool automatically creates an application directory (~/.sl_transit_repl) and downloads site data on first use.
Usage
Command Line Mode & REPL
To access the REPL run the command with no arguments; otherwise, pass a single argument (in quotes if necessary) and it will output the result and exit.
After installation:
# Get help
sl-repl --help
# Basic departure lookup
sl-repl "1002"
# Departure lookup with filters
sl-repl "1002 line:17 direction:1"
# Site lookup by name
sl-repl "lookup:name central"
# Site lookup by ID
sl-repl "lookup:id 1002"
# Custom app directory
sl-repl --app-dir ~/my_transit_data "1002"
From source (development):
python -m src.sl_transit_repl "1002"
python -m src.sl_transit_repl "lookup:name central"
Commands
Departure Queries
# Basic departure lookup
1002
# Filter by line (Green line)
1002 line:17
# Filter by direction and line
1002 line:17 direction:1
# Filter by transport mode
1002 transport:BUS
# Set forecast window (default: 60 minutes)
1002 forecast:30
# Show direction numbers in output
1002 show_numbers:true
# Debug mode (show HTTP headers)
1002 debug:true
# Find site by ID
lookup:id 1002
# Find sites by name (fuzzy search)
lookup:name odenplan
lookup:name central
lookup:name รฅkeshov
Example Sessions
Command Line Mode
# Quick departure check
$ sl-repl "1002 forecast:5"
Site: Centralen (1002)
โโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโ
โ Line โ Transport โ Direction โ Scheduled โ Expected โ Status โ Platform โ
โโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโค
โ 19 โ METRO โ Hรคsselby str โ 21:28 โ 21:28 โ ATSTOP โ 1 โ
โ 14 โ METRO โ Fruรคngen โ 21:29 โ 21:29 โ EXPECTED โ 2 โ
โโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโ
# Site search
$ sl-repl "lookup:name odenplan"
Sites matching 'odenplan'
โโโโโโโโฌโโโโโโโโโโโโฌโโโโโโโโโโฌโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโ
โ ID โ Name โ Aliases โ Abbreviation โ Coordinates โ
โโโโโโโโผโโโโโโโโโโโโผโโโโโโโโโโผโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโค
โ 9302 โ Odenplan โ โ ODE โ 59.3428, 18.0496 โ
โโโโโโโโดโโโโโโโโโโโโดโโโโโโโโโโดโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโ
Interactive REPL Mode
$ sl-repl
SL Transport REPL
Examples:
1002 (departure query: just site ID)
1002 line:17 direction:1 (departure query: with line and direction)
lookup:id 1002 (site lookup: find site by ID)
lookup:name odenplan (site lookup: find sites by name)
Enter 'quit' to exit
Use โ/โ arrows to access command history
Enter query: 1002 line:17
[Results displayed...]
Enter query: quit
Configuration
Time Thresholds
- Departure Forecast Duration: 60 minutes (default)
- Warning Threshold: 15 minutes (highlights urgent departures)
- Delay Threshold: 5 minutes (highlights significant delays)
API Integration
Uses official data from SL via the sites and depatures APIs from Trafiklab. No API key needed for these APIs, so try to be respectful in your usage ๐.
Class Usage
The tool is built around the SLTransitREPL class and thus could be imported for use in other scripts. Not exactly the intended usage, but knock yourself out.
from sl_transit_repl import SLTransitREPL
# Create REPL instance with default app directory
repl = SLTransitREPL()
# Or create REPL instance with custom app directory
repl = SLTransitREPL(app_dir="~/custom_transit_data")
# Run interactive session
repl.run()
# Execute single queries programmatically
success = repl.execute_query("1002 line:17")
success = repl.execute_query("lookup:name central")
# Or use individual methods programmatically
site = repl._find_site_by_id(1002)
sites = repl._find_sites_by_substring("central")
Files & Directory Structure
The application creates a hidden directory in your home folder:
~/.sl_transit_repl/ # Main application directory
โโโ cache/ # Cached API data
โ โโโ sites.json # Site data with fetch timestamps
โโโ .repl_history # Command history for auto-completion
File Descriptions
-
~/.sl_transit_repl/cache/sites.json: Cached site data from SL API with metadata including:- Site information (names, IDs, coordinates, aliases)
- Fetch timestamp for cache validation (24-hour expiry)
- Version information for future compatibility
-
~/.sl_transit_repl/.repl_history: Command history for the interactive REPL session- Enables โ/โ arrow key navigation through previous commands
- Persists between sessions
-
Configuration: Line colors, transport modes, and time thresholds are defined as class constants in the source code
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sl_transit_repl-0.1.0.tar.gz.
File metadata
- Download URL: sl_transit_repl-0.1.0.tar.gz
- Upload date:
- Size: 589.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0749bff01dea2ca357b381475b88440d7242235f5d671a8335699e330c16905
|
|
| MD5 |
189232d624ec467e68364f4122abc452
|
|
| BLAKE2b-256 |
37a385482907c74d5e8240b96deed002177da323d698d17ea538514fd1dbc190
|
File details
Details for the file sl_transit_repl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sl_transit_repl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
445ebedad1d77a14af3aee0322016c79d1a31563806c937dc9cf780b8e5bf807
|
|
| MD5 |
73156fc6e8f7bd40f2ec4c9fd37831b7
|
|
| BLAKE2b-256 |
4f45aa1e6fd68b1718a834cad2175c8e8fe1d884d71704d1c9e6667d7f948d44
|