SDKs overview

The Open Government, Finland portal (avoindata.fi) functions as a centralized hub for public sector open data in Finland. Its infrastructure is built upon the CKAN open-source data portal software, which includes a comprehensive CKAN API for programmatic interaction. This API enables developers to search for datasets, retrieve metadata, and access data resources directly, forming the primary interface for integrating with the platform.

While Open Government, Finland does not provide a suite of dedicated, officially branded SDKs, its reliance on the CKAN API means that developers can utilize existing CKAN client libraries or standard HTTP request libraries in their preferred programming language to interact with the portal. The documentation emphasizes direct API calls, offering code examples in common languages like Python, R, and JavaScript to guide developers in making these requests.

The CKAN API is a RESTful interface, supporting standard HTTP methods (GET, POST) for resource manipulation and data retrieval. This design facilitates integration with a wide range of development environments without requiring specific pre-built SDKs. Instead, developers can construct API requests using generic web client libraries, parsing the JSON responses that the API returns.

Official SDKs by language

Open Government, Finland does not offer official, branded SDKs. The portal's API is directly exposed via the underlying CKAN platform, which is a widely adopted open-source data portal solution. Therefore, interactions are typically performed by making direct HTTP requests to the CKAN API endpoints. This approach allows for flexibility in programming language choice, as any language capable of making web requests can interact with the API.

The Open Government, Finland API documentation provides examples for making these direct calls in languages such as Python, R, and JavaScript. These examples illustrate how to query datasets, retrieve package information, and access data resources. The following table outlines the general approach:

Language Package / Method Install Command / Usage Maturity
Python requests library / Direct HTTP pip install requests Stable (standard library use)
R httr, jsonlite libraries / Direct HTTP install.packages("httr"), install.packages("jsonlite") Stable (standard library use)
JavaScript fetch API / XMLHttpRequest / Direct HTTP Built-in browser functionality / Node.js node-fetch Stable (web standard)

Installation

Since Open Government, Finland relies on direct API interaction rather than dedicated SDKs, installation typically involves setting up standard HTTP client libraries in your chosen programming environment. These libraries are common tools for making web requests and parsing JSON data.

Python

For Python, the requests library is widely used for making HTTP requests. It can be installed via pip:

pip install requests

To handle JSON responses, Python's built-in json module is sufficient.

R

In R, the httr package provides a comprehensive set of tools for working with HTTP connections, and jsonlite is used for JSON parsing. Install them from CRAN:

install.packages("httr")
install.packages("jsonlite")

JavaScript

For browser-based JavaScript, the Fetch API is a modern, built-in method for making network requests. No installation is required. For Node.js environments, you might use node-fetch (if targeting older Node.js versions or specific features) or the built-in http/https modules, though axios is another popular third-party alternative:

npm install axios

For all languages, ensure your environment is set up to handle network requests and parse JSON data, as these are the fundamental requirements for interacting with the Open Government, Finland API.

Quickstart example

This example demonstrates how to fetch a list of all available datasets from the Open Government, Finland portal using Python. This uses the CKAN API's package_list endpoint to retrieve the identifiers of all datasets.

Python Example: Fetching Dataset List

First, ensure you have the requests library installed (pip install requests). Then, you can execute the following Python code:

import requests
import json

# The base URL for the Open Government, Finland CKAN API
api_base_url = "https://www.avoindata.fi/api/3/action/"

def get_dataset_list():
    endpoint = "package_list"
    url = f"{api_base_url}{endpoint}"

    try:
        response = requests.get(url)
        response.raise_for_status()  # Raise an exception for HTTP errors (4xx or 5xx)
        data = response.json()

        if data['success']:
            print("Successfully retrieved dataset list.")
            print(f"Total datasets: {len(data['result'])}")
            # Print the first 5 dataset names for brevity
            print("First 5 datasets:")
            for dataset_name in data['result'][:5]:
                print(f"- {dataset_name}")
        else:
            print(f"API request failed: {data.get('error', 'Unknown error')}")

    except requests.exceptions.HTTPError as http_err:
        print(f"HTTP error occurred: {http_err}")
    except requests.exceptions.ConnectionError as conn_err:
        print(f"Connection error occurred: {conn_err}")
    except requests.exceptions.Timeout as timeout_err:
        print(f"Timeout error occurred: {timeout_err}")
    except requests.exceptions.RequestException as req_err:
        print(f"An error occurred: {req_err}")
    except json.JSONDecodeError:
        print("Failed to decode JSON response.")

if __name__ == "__main__":
    get_dataset_list()

This script constructs the URL for the package_list endpoint, makes a GET request, and then parses the JSON response to extract and print the names of the datasets. Error handling is included to manage potential network issues or API failures.

Community libraries

Given that Open Government, Finland utilizes the CKAN platform, many community-contributed libraries and tools developed for CKAN in general can be used to interact with the portal. These libraries often wrap the raw CKAN API calls, providing a more abstract and developer-friendly interface.

Python CKAN Client Libraries

  • ckanapi: This is a widely used Python client library for the CKAN API. It simplifies making API calls and handling responses, abstracting away the direct HTTP requests. While not officially maintained by Open Government, Finland, it is compatible with their CKAN instance. Installation is typically via pip: pip install ckanapi. It supports both read and write operations (with appropriate API keys for write access).
  • ckan-python: Another Python binding for the CKAN API, offering similar functionality to ckanapi. Developers can choose based on preference and specific project requirements.

R CKAN Client Libraries

  • ckanr: An R package designed to interact with CKAN instances. It provides functions to search for datasets, retrieve metadata, and download resources, making it easier for R users to integrate Open Government, Finland data into their analysis workflows. It can be installed from CRAN: install.packages("ckanr").

JavaScript/TypeScript CKAN Client Libraries

  • While a single dominant JavaScript CKAN client library is less prevalent than in Python or R, various open-source projects and utilities exist that wrap CKAN API calls for web and Node.js applications. Developers often opt for generic HTTP clients like axios or the browser's native fetch API, combined with custom utility functions, to interact with the CKAN API, as demonstrated in the Open Government, Finland API documentation examples.

When using community libraries, it is advisable to consult their respective documentation and community support channels for specific usage instructions and compatibility notes. These libraries can significantly reduce the amount of boilerplate code required to interact with the Open Government, Finland API, streamlining development efforts.