SDKs overview
The Open Government, Queensland Government initiative provides access to a wide range of public datasets. While a comprehensive, single SDK covering all datasets and functionalities is not offered, access is primarily facilitated through the underlying CKAN (Comprehensive Knowledge Archive Network) platform's API. CKAN is an open-source data portal software that allows for the publication, sharing, and use of data as detailed in the CKAN DataStore documentation. Developers can interact with the Queensland Government's data portal using standard web requests to the CKAN DataStore API, or by utilizing language-specific libraries that wrap these API calls.
The Queensland Government's data portal provides detailed guidance on data publishing and access. This includes information on how datasets are structured and the various formats available for download, such as CSV, XML, and JSON. For programmatic access, the DataStore API allows structured querying of tabular data, enabling filtering, sorting, and pagination of results. The API adheres to RESTful principles, using standard HTTP methods for data retrieval.
The availability of specific API endpoints and their documentation can vary by dataset, as publishers within the Queensland Government define their own data structures and access methods. Developers are encouraged to consult the individual dataset pages on the Queensland Government data portal for precise API details and examples relevant to the data they wish to consume.
Official SDKs by language
While the Open Government, Queensland Government data portal itself does not publish a suite of officially maintained, language-specific SDKs, it relies on the open-source CKAN ecosystem. The primary 'official' method of interaction is direct API calls to the CKAN DataStore API, which is documented within the portal's technical guidelines and on individual dataset pages. However, several tools and libraries are widely recognized and supported by the CKAN community, which can be considered de facto official for practical purposes when interacting with CKAN-based portals.
The table below outlines common approaches and libraries used to interact with CKAN-based data portals, including the Queensland Government's:
| Language | Package/Method | Install Command (Example) | Maturity |
|---|---|---|---|
| Python | ckanapi library |
pip install ckanapi |
Stable, actively maintained community project |
| R | ckanr library |
install.packages("ckanr") |
Stable, actively maintained community project |
| JavaScript (Node.js/Browser) | Direct Fetch/Axios (REST API) | npm install axios (for Node.js) |
Standard web technology |
| PHP | Guzzle HTTP Client (REST API) | composer require guzzlehttp/guzzle |
Standard web technology |
| Ruby | httparty gem (REST API) |
gem install httparty |
Standard web technology |
These libraries abstract the HTTP request process, handle JSON parsing, and provide convenient methods for interacting with CKAN's various API endpoints, including the DataStore. For example, the ckanapi library for Python offers methods to search datasets, retrieve resources, and query the DataStore with parameters like filters and limits. While not branded as 'Queensland Government SDKs,' these tools are the recommended way to programmatically access the data portal's resources.
Installation
Installation procedures for interacting with the Open Government, Queensland Government data portal typically involve installing a language-specific HTTP client or a CKAN-specific library. The most common environments are Python and R due to their prevalence in data science and analysis.
Python
For Python developers, the ckanapi library is a widely used client for CKAN portals. It simplifies interaction with the CKAN API, including the DataStore API for tabular data.
pip install ckanapi
This command installs the ckanapi package and its dependencies from the Python Package Index (PyPI). It is recommended to use a virtual environment to manage project dependencies as described in the Python venv tutorial.
R
R users can leverage the ckanr package, which provides a comprehensive interface to CKAN API functions, including data retrieval from the DataStore.
install.packages("ckanr")
This command installs the ckanr package from CRAN (The Comprehensive R Archive Network). Once installed, the package can be loaded into an R session using library(ckanr).
JavaScript (Node.js/Browser)
For JavaScript environments, direct HTTP requests are common. Libraries like axios or the native fetch API can be used to interact with the RESTful CKAN DataStore API.
npm install axios
After installation, axios can be imported and used to make GET requests to the CKAN API endpoints. The fetch API is built into modern browsers and Node.js environments from v18.0.0, requiring no installation as documented by MDN Web Docs.
Other Languages
For other programming languages such as PHP, Ruby, or Java, developers typically use general-purpose HTTP client libraries (e.g., Guzzle for PHP, HTTParty for Ruby) to construct and send requests to the CKAN DataStore API and parse the JSON responses. The specific installation steps will depend on the language's package manager (e.g., Composer for PHP, Bundler for Ruby).
Quickstart example
This quickstart example demonstrates how to retrieve data from a hypothetical dataset on the Open Government, Queensland Government data portal using Python with the ckanapi library. This example assumes a dataset with a resource ID is available and accessible via the CKAN DataStore API. The Queensland Government's data portal URL is https://www.data.qld.gov.au/.
Python with ckanapi
First, ensure you have ckanapi installed:
pip install ckanapi
Then, use the following Python code to query a dataset resource. You will need to replace 'YOUR_RESOURCE_ID' with an actual resource ID from a dataset on the Queensland Government data portal. Resource IDs are typically found on the individual dataset's page under the 'Data and Resources' section.
from ckanapi import RemoteCKAN
# Initialize a RemoteCKAN object pointing to the Queensland Government data portal
# The base URL for the CKAN API is typically /api/3 on the portal.
ua = 'ckanapi/1.0 (+https://www.data.qld.gov.au/)' # User agent string
ckan = RemoteCKAN('https://www.data.qld.gov.au/', user_agent=ua)
# Replace 'YOUR_RESOURCE_ID' with the actual resource ID of the dataset you want to query
resource_id = 'YOUR_RESOURCE_ID' # Example: 'a1b2c3d4-e5f6-7890-1234-567890abcdef'
try:
# Query the DataStore for records from the specified resource
# You can add parameters like 'limit', 'offset', 'filters' etc.
result = ckan.action.datastore_search(resource_id=resource_id, limit=5)
print(f"Successfully retrieved {len(result['records'])} records from resource ID: {resource_id}")
print("Records:")
for record in result['records']:
print(record)
# To get more information about the fields (columns) in the dataset
print("\nFields:")
for field in result['fields']:
print(f" Name: {field['id']}, Type: {field['type']}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure 'YOUR_RESOURCE_ID' is a valid resource ID from data.qld.gov.au that supports the DataStore API.")
print("You can find resource IDs on individual dataset pages under the 'Data and Resources' section.")
# Example of searching for datasets by keyword
try:
search_results = ckan.action.package_search(q='transport', rows=3)
print(f"\nFound {search_results['count']} packages matching 'transport'. Top 3:")
for pkg in search_results['results']:
print(f" Title: {pkg['title']} (ID: {pkg['id']})")
except Exception as e:
print(f"An error occurred during package search: {e}")
This script first initializes a connection to the CKAN portal. It then attempts to fetch the first 5 records from a specified dataset resource using its ID. It also demonstrates how to search for datasets by a keyword, which can be useful for discovering relevant data programmatically. Remember that not all datasets are available through the DataStore API; some may only offer direct file downloads.
Community libraries
The Open Government, Queensland Government data portal, being built on CKAN, benefits from a broader ecosystem of community-developed libraries and tools. These libraries often extend functionality, provide alternative language bindings, or offer specialized data processing capabilities.
- CKAN Extensions: The CKAN platform supports a modular architecture, allowing developers to create CKAN extensions for custom features. While these are typically server-side, they can influence client-side interaction by exposing new API endpoints or modifying existing data structures.
- Data Visualization Tools: Many general-purpose data visualization libraries (e.g., D3.js for JavaScript, Matplotlib/Seaborn for Python, ggplot2 for R) can consume data retrieved from the Queensland Government portal. Developers often integrate these to create custom dashboards and analytical tools. For example, a Python script might pull data using
ckanapiand then usepandasfor data manipulation andmatplotlibfor plotting. - ETL (Extract, Transform, Load) Tools: Various open-source and commercial ETL tools can be configured to connect to RESTful APIs like the CKAN DataStore API. These tools can automate the process of extracting data, transforming it into a desired format, and loading it into a database or data warehouse for further analysis.
- Jupyter Notebooks: Data scientists frequently use Jupyter Notebooks (or similar environments like RStudio) to interact with CKAN portals. These environments allow for iterative development, combining code, visualizations, and explanatory text in a single document, making them ideal for exploring government datasets.
When using community-developed libraries, it's important to verify their maintenance status, documentation, and compatibility with the specific version of CKAN running on the Queensland Government data portal. While these tools can greatly enhance productivity, they may not offer the same level of support as officially maintained software.