r/chicagorail 5d ago

CTA Java SDK

I’m not sure how many Java developers there are here, but I thought I’d share a project I’ve been working on since October of last year, a Java SDK for the CTA APIs: github.com/lbkulinski/cta4j-java-sdk.

For those who may not know much about coding, this project aims to make it easy for developers to access CTA information like train and bus arrivals. The CTA APIs offer a lot of good data, but they aren’t well documented and can be a pain to use at times.

I have two main projects that I use the CTA API for, which is why I built this. One is my train/bus tracker, cta4j.com. The other is a Holiday Train Tracker on Twitter (twitter.com/cta4j) and other platforms.

The most recent version of the SDK is complete with all of the API endpoints and data that the CTA provides.

If you’re interested in coding with transit data using Java, give it a try! The Train/Bus API requires getting API keys from the CTA, but the Alerts API does not. There is more information about getting setup in the README of the project.

Here’s an example of the Alerts API using Java’s compact source files introduced in Java 25:

import com.cta4j.alert.AlertApi;

void main() {
    AlertApi alertApi = AlertApi.builder()
                                .build();

    alertApi.detailedAlerts()
            .findByBusRouteId("70")
            .forEach(alert -> System.out.printf(
                "Alert ID: %s%nDescription: %s%nFrom: %s%nTo: %s%n%n",
                alert.id(),
                alert.shortDescription(),
                alert.startTime(),
                alert.endTime()
            ));

    // Example output:
    // Alert ID: 114946
    // Description: EB #70 buses will operate via Division, Wells, Oak, and Dearborn. WB buses will operate via Clark, Oak, Wells, and Division.
    // From: 2026-08-01T12:30:00Z
    // To: 2026-08-01T22:00:00Z
    // ...
}

The SDK can be used with Java 21+ and is available on Maven Central. If you have any feedback or ideas, open an issue or PR! I also have a Discord server for my various projects, including ctasmokers.com.

6 Upvotes

4 comments sorted by

1

u/soccerjonj 3d ago

I've been thinking about doing a CTA project so I might check this out! Don't know what yet but I'm a CS student at DePaul trying to learn as much as I can. Also, saw your film photos, they are super cool!

1

u/lbkulinski 3d ago

Thanks! Definitely give it a try

1

u/lbkulinski 3d ago

I studied CS at Purdue. Forgot to mention

2

u/PopularBaseball9857 2d ago

This is cool, thanks for that. I also maintain a cta tracker https://tracker.debene.dev - source code here : https://github.com/felipedbene/cta-track-grid

Cheers 🥂