API
From CKAN
Use the CKAN API to get at the data catalogue programmatically. In your own web page or program you can:
- Get any bit of CKAN data
- Edit CKAN data
- Create a whole new web front-end for CKAN (if you want!)
Examples of use:
- The Linked Open Data cloud is drawn with a script that gets the dataset info from CKAN: http://thedatahub.org/group/lod
- Open Spending scripts scan the CKAN API at http://catalogue.data.gov.uk/ for spending datasets and present them here: http://data.gov.uk/openspending
- data.gov.uk has PHP to get datasets from the CKAN API at http://catalogue.data.gov.uk/ API to get datasets and load them into a CMS
- data.gov.uk has a python script that reads the datasets from the Office of National Statistics and loads them into CKAN at data.gov.uk using the API.
The official reference documentation for the CKAN API is in the Administrator Manual: http://docs.ckan.org/en/latest/api.html
This page provides additional information and an overview.
Contents |
Introduction to the CKAN API
To use a the CKAN API, your application will make an HTTP request and parse the response. By default, the response format is JSON. Most of the API is RESTful and your methods will be the standard HTTP methods like GET, PUT, POST and DELETE.
CKAN's APIs provide access to all of the objects in the CKAN Domain Model. The standard access url is:
/api/rest/{object-name}/{object-id}
There are API endpoints for:
API Reference Documentation
See the CKAN Administration Guide for the CKAN API Reference: http://docs.ckan.org/en/latest/api.html
Tutorial
API Client Libraries
There exist clients for the CKAN API in several languages
Javascript Client
The CKAN API can just be used directly from jquery. However, for more sophisticated uses -- as well as a source of code examples -- you may wish to check out the CKAN Javascript client library:
Python client
The Python client is officially maintained by the CKAN core developers.
- Code: http://pypi.python.org/pypi/ckanclient
- Docs: http://ckan.org/documentation.
- Author: CKAN team
Command-line client
Datapkg allows you to download the data in CKAN packages on the command-line, in the style of software package managers (e.g. apt-get, cpan, pypi).
- Docs: http://packages.python.org/datapkg/
- Source: http://bitbucket.org/okfn/datapkg
- Author: CKAN team
PHP client
Ckan_client-PHP is an almost full and (I hope) easy-to-use interface to the CKAN APIs.
- Source: http://github.com/jeffreybarke/Ckan_client-PHP
- Author: Jeffrey Barke This example uses CKAN's search API and lists and reads Packages/Groups with the REST API.
Perl client example
This example accesses the CKAN REST API to get a list of the packages, count the uses of an 'extra' field and then plots it with the Google chart API. Luke broke the CKAN bits out into a CKAN specific client library - Net::CKAN.
Luke is open to improving this library and eventually releasing it to CPAN.
- Script Source: http://github.com/lukec/net-ckan/blob/master/bin/make-ckan-chart
- Library Source: http://github.com/lukec/net-ckan/blob/master/lib/Net/CKAN.pm
- Info: http://lists.okfn.org/pipermail/ckan-discuss/2010-February/000057.html
- Author: Luke Closs
Drupal module
A Drupal module for integrating with CKAN.
Advanced module:
- Blog post
- ckanpackage.tar.gz (and available on drupal.org)
- Author: Data.gov.uk
Simple module:
Other Examples of Using the API
- http://www.practicalweb.co.uk/blog/10/02/23/accessing-ckan-data-php
- Author: http://practicalweb.co.uk/ Sean Burlington