Skip to main content

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. SL Transit REPL

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

SL Transit REPL SL Transit REPL

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sl_transit_repl-0.1.0.tar.gz (589.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sl_transit_repl-0.1.0-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

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

Hashes for sl_transit_repl-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e0749bff01dea2ca357b381475b88440d7242235f5d671a8335699e330c16905
MD5 189232d624ec467e68364f4122abc452
BLAKE2b-256 37a385482907c74d5e8240b96deed002177da323d698d17ea538514fd1dbc190

See more details on using hashes here.

File details

Details for the file sl_transit_repl-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sl_transit_repl-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 445ebedad1d77a14af3aee0322016c79d1a31563806c937dc9cf780b8e5bf807
MD5 73156fc6e8f7bd40f2ec4c9fd37831b7
BLAKE2b-256 4f45aa1e6fd68b1718a834cad2175c8e8fe1d884d71704d1c9e6667d7f948d44

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page