Skip to content

rlvelte/dotbahn

Repository files navigation

logo

DotBahn - .NET Client for Deutsche Bahn APIs

NuGet NuGet NuGet Docs

DotBahn is a collection of .NET client libraries for accessing Deutsche Bahn (DB) APIs. Query train schedules, station details, and facility status directly from your application.

Available clients:

  • Stations (StaDa): Station data including parking, accessibility, and opening hours.
  • Facilities (FaSta): Real-time operational status of elevators and escalators at stations.
  • Timetables: Scheduled departures and arrivals with real-time delay and platform change information.

Table of Contents

Install

Install the packages you need from NuGet or GitHub Packages:

dotnet add package DotBahn.Timetables
dotnet add package DotBahn.Stations
dotnet add package DotBahn.Facilities

Usage

Dependency Injection (Recommended)

All packages integrate seamlessly with ServiceCollection. Each client comes with a default endpoint, override only for custom proxies:

// Register clients
services.AddDotBahnStations();
services.AddDotBahnTimetables();
services.AddDotBahnFacilities();

// Configure authorization (required for API access)
services.AddDotBahnAuthorization(opt => {
    opt.ClientId = clientId;
    opt.ApiKey = clientSecret;
});

// ---

// Optional: override default endpoints
services.AddDotBahnStations(opt => {
    opt.BaseEndpoint = new Uri("https://custom-proxy.example.com/stada");
});

Manual Initialization

Create client instances directly without dependency injection. Each client creates and owns its own HttpClient:

using var client = new StationClient(
    new ClientOptions {
        BaseEndpoint = new Uri("https://apis.deutschebahn.com/db-api-marketplace/apis/station-data/v2/")
    },
    new AuthorizationOptions {
        ClientId = clientId,
        ApiKey = clientSecret
    });

Samples

ICE Monitor

A terminal-based departure board for ICE trains at a given station. Displays train numbers, scheduled and actual departure times, platforms, destinations, and routes. Highlights delays and platform changes in real time. Refreshes automatically every 2 minutes.

dotnet run --project samples/DotBahn.Samples.IceMonitor -- <EVA> <your-client-id> <your-client-secret>

Station Browser

An interactive terminal application for exploring DB station details. Search by name and navigate results with arrow keys. Shows station category, identifiers (EVA/RIL100), address, coordinates, regional area, available services, and real-time elevator/escalator status.

dotnet run --project samples/DotBahn.Samples.StationBrowser -- <SearchName> <your-client-id> <your-client-secret>

Authorization

A Deutsche Bahn API key is required. Register and obtain your credentials at the DB API Marketplace.

About

NuGet packages for Deutsche Bahn APIs, organized into three packages: Timetables (schedules), StaDa (station data), and FaSta (facility information).

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors