SDKs overview
Software Development Kits (SDKs) for Open Government, New Zealand provide a structured approach to programmatically access and interact with the platform's Application Programming Interfaces (APIs). These SDKs are designed to simplify common development tasks, such as authentication, request formatting, response parsing, and error handling. By abstracting the intricacies of direct HTTP requests and JSON payload management, SDKs enable developers to focus on application logic rather than low-level API communication. Open Government, New Zealand offers official SDKs for several popular programming languages, alongside a growing ecosystem of community-maintained libraries.
The SDKs typically include client libraries that encapsulate API endpoints as language-specific methods, data models that map API responses to native objects, and utilities for managing authentication tokens. For instance, the OAuth 2.0 authorization framework is commonly used for secure API access, and SDKs often include built-in support for handling token exchange and refresh processes, as detailed in the OAuth 2.0 specification. This integration streamlines the development workflow for applications requiring secure access to government data and services.
Official SDKs by language
Open Government, New Zealand provides official SDKs developed and maintained by the platform's team to ensure compatibility and adherence to API specifications. These SDKs are the recommended method for integrating with the platform due to their direct support, regular updates, and comprehensive documentation. Each SDK is tailored to the conventions and best practices of its respective programming language, aiming to offer a natural development experience.
The following table outlines the official SDKs available, including their primary language, package name, typical installation command, and current maturity status:
| Language | Package Name | Install Command | Maturity |
|---|---|---|---|
| Python | opengov-nz-python |
pip install opengov-nz-python |
Stable |
| JavaScript | @opengov-nz/js-sdk |
npm install @opengov-nz/js-sdk |
Stable |
| Ruby | opengov-nz-ruby |
gem install opengov-nz-ruby |
Beta |
| Go | opengov.nz/sdk/go |
go get opengov.nz/sdk/go |
Beta |
These official SDKs are hosted in respective package managers and version control systems, with detailed documentation available on the Open Government, New Zealand developer portal. Developers are encouraged to consult the official Open Government, New Zealand developer documentation for the most up-to-date information on SDK features, usage, and release notes.
Installation
Installing an Open Government, New Zealand SDK typically follows the standard practices for package management within each programming language ecosystem. The process involves using a language-specific package manager to download and integrate the SDK into your project.
Python SDK Installation
For Python projects, the pip package installer is used. Ensure you have Python and pip installed on your system. To install the official Python SDK:
pip install opengov-nz-python
It is often recommended to use a virtual environment to manage project dependencies, preventing conflicts with other Python projects. You can create and activate a virtual environment before installation:
python3 -m venv .venv
source .venv/bin/activate
pip install opengov-nz-python
JavaScript SDK Installation
For JavaScript and Node.js projects, npm (Node Package Manager) or yarn are the primary tools. Ensure Node.js and one of these package managers are installed. To install the official JavaScript SDK:
npm install @opengov-nz/js-sdk
# or with yarn
yarn add @opengov-nz/js-sdk
This command adds the SDK as a dependency to your package.json file and downloads it into your node_modules directory.
Ruby SDK Installation
Ruby projects utilize RubyGems for package management. Ensure Ruby and Bundler (for managing project dependencies) are installed. To install the official Ruby SDK:
gem install opengov-nz-ruby
If you are using Bundler, add the gem to your Gemfile:
# Gemfile
gem 'opengov-nz-ruby'
Then run bundle install to install the gem.
Go SDK Installation
For Go projects, the Go module system is used for dependency management. Ensure Go is installed and your project is initialized as a Go module. To install the official Go SDK:
go get opengov.nz/sdk/go
This command downloads the module and adds it to your go.mod file. After installation, you can import the package in your Go source files.
Quickstart example
This quickstart example demonstrates how to use the Python SDK to fetch a list of publicly available datasets from the Open Government, New Zealand platform. This assumes the opengov-nz-python SDK has been installed and you have an API key configured for access, if required by the specific endpoint.
First, ensure your API key is available. For development, it might be stored as an environment variable or loaded from a configuration file. For production, secure handling of API keys, such as through secrets management services, is recommended. For example, AWS offers AWS Secrets Manager for securely storing and retrieving credentials.
import os
from opengov_nz_python import OpenGovClient
# It's recommended to load API_KEY from environment variables for security
API_KEY = os.environ.get('OPENGOV_NZ_API_KEY')
if not API_KEY:
print("Error: OPENGOV_NZ_API_KEY environment variable not set.")
exit(1)
try:
# Initialize the client with your API key
client = OpenGovClient(api_key=API_KEY)
# Fetch a list of datasets
# The specific method and parameters will depend on the API documentation
# This is an illustrative example for a 'datasets' endpoint.
print("Fetching datasets...")
datasets = client.datasets.list(limit=10, offset=0)
if datasets:
print(f"Successfully fetched {len(datasets)} datasets:")
for i, dataset in enumerate(datasets):
print(f" Dataset {i+1}:")
print(f" ID: {dataset.id}")
print(f" Title: {dataset.title}")
print(f" Description: {dataset.description[:75]}...")
print(f" URL: {dataset.url}")
print("\n")
else:
print("No datasets found or an empty list was returned.")
except Exception as e:
print(f"An error occurred: {e}")
This Python snippet demonstrates the basic workflow:
- Import the necessary client from the SDK.
- Retrieve the API key, ideally from a secure environment variable.
- Initialize the SDK client with the API key.
- Call a method on the client (e.g.,
client.datasets.list()) to interact with a specific API endpoint. - Process the returned data, which typically comes as Python objects populated by the SDK.
- Include error handling for robust application behavior.
Always refer to the official Open Government, New Zealand API reference for precise endpoint details, required parameters, and response structures for each service you intend to use.
Community libraries
Beyond the official SDKs, the Open Government, New Zealand developer community contributes a variety of libraries and tools that extend integration possibilities. These community-driven projects can offer support for additional programming languages, specialized functionalities, or alternative approaches to interacting with the Open Government, New Zealand APIs. While not officially supported, these libraries can be valuable resources, often providing quick solutions or filling gaps where official SDKs might not yet exist.
Examples of common community contributions include:
- PHP Client Libraries: Developers have created libraries that wrap the RESTful APIs in PHP classes, facilitating integration for web applications built with frameworks like Laravel or Symfony.
- C#/.NET Wrappers: For developers working in the .NET ecosystem, community-maintained NuGet packages provide C# clients to interact with various Open Government, New Zealand services.
- CLI Tools: Command-line interface tools developed by the community can enable quick data retrieval or task automation directly from the terminal, useful for scripting and administrative tasks.
- Data Connectors: Some community projects focus on creating connectors for popular data analysis tools or business intelligence platforms, allowing for easier ingestion and visualization of Open Government, New Zealand data.
When considering a community library, it is important to evaluate its maintenance status, documentation quality, and active development. Checking the project's repository (e.g., on GitHub) for recent commits, open issues, and pull requests can provide insight into its reliability. While official SDKs offer guaranteed compatibility, community libraries can sometimes provide more flexibility or address niche requirements. Developers should consult community forums or the Open Government, New Zealand developer portal for lists and discussions surrounding these third-party tools.
The Open Government, New Zealand platform encourages community contributions and often highlights well-maintained or particularly useful projects through its developer resources. However, users of community libraries assume responsibility for their integration and long-term maintenance, as they do not fall under the official support umbrella.