Skip to content

Monorepo for Swedish public transport tools, built on Trafiklab APIs.

License

Notifications You must be signed in to change notification settings

rebelliard/transit-se

Repository files navigation

Transit SE

Monorepo for Swedish public transport tools, built on Trafiklab APIs.

Supported APIs

API What it does Auth Coverage Update frequency
SL Transport Departures, sites, lines, stop points None Stockholm Real-time
SL Deviations Disruptions, reroutes, maintenance None Stockholm Real-time
Trafiklab Stops Search stops by name, list all stops TRAFIKLAB_API_KEY Sweden Static
Trafiklab Timetables Departures and arrivals with delays TRAFIKLAB_API_KEY Sweden Real-time
GTFS-RT Alerts Service alerts (disruptions, reroutes) TRAFIKLAB_GTFS_KEY Sweden ~15 sec
GTFS-RT Trip Updates Per-trip delays, cancellations, predictions TRAFIKLAB_GTFS_KEY Sweden ~15 sec
GTFS-RT Vehicle Positions Live GPS, speed, bearing, occupancy TRAFIKLAB_GTFS_KEY Sweden ~3 sec
Combined Nearby Vehicles near a location with mode classification TRAFIKLAB_GTFS_KEY Stockholm Real-time

Stockholm (SL) APIs work without any keys. For other Swedish operators (Uppsala, Skane, etc.), use the GTFS-RT APIs.

Packages

Package Description Docs
@transit-se/sdk TypeScript SDK for Trafiklab realtime APIs README
@transit-se/mcp MCP server — exposes the SDK as AI-callable tools README

Quick Start

SDK

import { TransitClient } from '@transit-se/sdk';

const client = new TransitClient({ apiKey: process.env.TRAFIKLAB_API_KEY! });

const stops = await client.stops.searchByName('T-Centralen');
const deps = await client.timetables.getDepartures('740000001');
const slDeps = await client.sl.getDepartures(9192); // no key needed

See the SDK README for the full API reference.

MCP Server

Add to your MCP client config (no installation required):

{
  "mcpServers": {
    "transit-se": {
      "command": "npx",
      "args": ["-y", "@transit-se/mcp"],
      "env": {
        "TRAFIKLAB_API_KEY": "your-key-here",
        "TRAFIKLAB_GTFS_KEY": "your-key-here"
      }
    }
  }
}

See the MCP README for detailed setup instructions for Claude Desktop, Claude Code, and Cursor.

Credentials

The SL APIs (Transport, Deviations) work without any API key. The other APIs each require a Trafiklab key:

Key Trafiklab product Unlocks
TRAFIKLAB_API_KEY Trafiklab Realtime APIs Stop Lookup, Timetables
TRAFIKLAB_GTFS_KEY GTFS Sweden 3 Realtime Service Alerts, Trip Updates, Vehicle Positions, Nearby Vehicles
  1. Sign up at developer.trafiklab.se
  2. Create a project and enable the API products you need
  3. Copy your API keys from the project dashboard
cp .env.example .env
# Edit .env and paste your keys

Development

git clone git@github.com:rebelliard/transit-se.git
cd transit-se
bun install
Command Description
bun run check Type-check + lint
bun run test Run all tests
bun run --filter @transit-se/mcp inspect Open the MCP Inspector web UI
bun run --filter @transit-se/sdk inspect Open the SDK Swagger UI

License

MIT — Data provided by Trafiklab.se under CC-BY 4.0.

About

Monorepo for Swedish public transport tools, built on Trafiklab APIs.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors