SDKs overview

Transport for Norway, operated by Entur, provides access to national public transport data through a suite of APIs, including the Journey Planner, Real-time Data, and Stop Place APIs. To facilitate developer integration, Entur offers official Software Development Kits (SDKs) and supports community-driven libraries. These SDKs are designed to abstract the complexities of API calls, authentication, and data parsing, allowing developers to focus on application logic rather than HTTP requests and JSON manipulation.

The primary goal of these SDKs is to streamline the development of applications that utilize Norwegian public transport information, such as journey planning tools, real-time departure boards, and mobility-as-a-service (MaaS) platforms. Developers can find comprehensive documentation and an API playground on the official Entur developer portal, which covers the underlying API specifications.

While Entur primarily focuses on Norway-specific transport data, the underlying architectural patterns of its APIs, often leveraging technologies like GraphQL for flexible data querying and JSON:API for structured responses, are common in modern API design. This familiarity can assist developers experienced with other transport data platforms, such as those offered by Google Maps Platform or HERE Technologies, in quickly adapting to Entur's ecosystem.

Official SDKs by language

Entur provides official SDKs to ensure robust and up-to-date integration with their APIs. These SDKs are maintained by Entur and offer the most reliable way to interact with the Transport for Norway data. The following table details the officially supported SDKs:

Language Package Name Install Command (Example) Maturity / Status
JavaScript / Node.js @entur/sdk npm install @entur/sdk or yarn add @entur/sdk Stable, Actively Maintained
Python entur-client pip install entur-client Stable, Actively Maintained
Kotlin / JVM entur-api-client Add to build.gradle or pom.xml (see Entur documentation for specifics) Stable, Actively Maintained

Each official SDK is designed to encapsulate the API's intricacies, including authentication mechanisms, rate limiting considerations, and error handling. Developers are encouraged to refer to the specific documentation for each SDK on the Entur developer portal for detailed usage instructions and API method references.

Installation

Installation of the official SDKs follows standard package management practices for their respective languages. Below are typical installation methods for the primary official SDKs:

JavaScript / Node.js

For Node.js projects, use npm or yarn to add the @entur/sdk package:

npm install @entur/sdk
# or
yarn add @entur/sdk

After installation, you can import the necessary modules into your JavaScript or TypeScript files.

Python

Python developers can install the entur-client package using pip:

pip install entur-client

This will install the client along with its dependencies, making it available for import in your Python scripts.

Kotlin / JVM

For Kotlin and other JVM-based projects, the entur-api-client is typically integrated via a build tool like Gradle or Maven. You'll need to add the dependency to your project's build file. For Gradle (Kotlin DSL), it might look like this in your build.gradle.kts file:

dependencies {
    implementation("org.entur:entur-api-client:VERSION") // Replace VERSION with the latest release
}

Refer to the official Entur API documentation for the most current version number and specific setup instructions for Maven or other build systems.

Quickstart example

This example demonstrates how to use the JavaScript/Node.js SDK to fetch real-time departure information for a specific stop. Before running, ensure you have installed the @entur/sdk using the instructions above and have obtained API credentials from the Entur developer portal.

const { EnturClient } = require('@entur/sdk');

// Replace with your actual API key and client name
const API_KEY = 'YOUR_ENTUR_API_KEY';
const CLIENT_NAME = 'YourAppName'; // e.g., 'MyJourneyPlannerApp-V1'

const entur = new EnturClient({
  apiKey: API_KEY,
  clientName: CLIENT_NAME,
});

// Example: Fetch real-time departures for Oslo Central Station (Jernbanetorget stop place)
// Replace 'NSR:StopPlace:58366' with the desired Stop Place ID from the Stop Place API
const stopPlaceId = 'NSR:StopPlace:58366'; 

async function getDepartures() {
  try {
    const response = await entur.journeyPlanner.getDepartures({ 
      id: stopPlaceId,
      numberOfDepartures: 5,
    });

    console.log(`
Real-time departures for ${stopPlaceId}:
`);

    if (response.data.stopPlace.estimatedCalls.length === 0) {
      console.log('No upcoming departures found.');
      return;
    }

    response.data.stopPlace.estimatedCalls.forEach(call => {
      const departureTime = new Date(call.expectedDepartureTime).toLocaleTimeString('no-NO');
      const destination = call.destinationDisplay.frontText;
      const serviceJourney = call.serviceJourney.journeyPattern.line.publicCode || call.serviceJourney.journeyPattern.line.name;

      console.log(`  ${departureTime} - Line ${serviceJourney} to ${destination}`);
    });

  } catch (error) {
    console.error('Error fetching departures:', error.message);
    if (error.response) {
        console.error('API Error Response:', error.response.data);
    }
  }
}

getDepartures();

This snippet initializes the EnturClient with credentials and then calls the getDepartures method, which corresponds to the Real-time Data API. It retrieves the next five departures for a specified stop place and logs them to the console. Developers should ensure their API key and client name are correctly configured and manage them securely in production environments, as outlined in general API key security best practices.

Community libraries

Beyond the official SDKs, the developer community has contributed various libraries and wrappers that interact with the Transport for Norway APIs. These community-driven projects can offer alternative language support, specialized functionality, or simplified interfaces for specific use cases. While not officially supported or maintained by Entur, they often address niche requirements or provide quick prototyping capabilities.

Common places to find community libraries include:

  • GitHub: Many open-source community projects are hosted on GitHub. Searching for terms like "entur api" or "transport norway sdk" can yield relevant repositories. Developers should evaluate the project's activity, documentation, and maintainer responsiveness before integrating into a production system.
  • Package Managers: Language-specific package repositories (e.g., PyPI for Python, npm for Node.js, Maven Central for JVM) may host community contributions.
  • Developer Forums and Community Boards: Discussions on transport API development or Norwegian tech communities might occasionally highlight useful community-made tools.

When considering a community library, it is advisable to:

  • Check the last commit date to assess active maintenance.
  • Review open issues and pull requests to understand community engagement and potential unresolved bugs.
  • Verify compatibility with the latest API versions as documented on the Entur developer portal.
  • Examine the license to ensure it aligns with your project's requirements.

As community libraries are not officially endorsed, developers assume responsibility for their stability and security. For mission-critical applications, using the official SDKs is generally recommended due to their guaranteed support and alignment with the latest API specifications.