skip to navigation
skip to content

Not Logged In

ckan-api-client 0.1-beta2

Client for the Ckan API

Latest Version: 0.1-beta5

This package provides a client for the ckan API.

Specifically, it includes:

  • a low-level client, which is pretty much just a wrapper around HTTP calls, handling serialization and exception-raising.
  • a high-level client, attempting to make it easier / safer to perform certain operations on a ckan catalog.
  • a synchronization client, used to provide some automation for synchronization tasks of collections of datasets into a catalog (commonly referred to as “harvesting”).

Other than that, it attempts to get work around some common issues with that API, such as inconsistencies and bugs, trying to make sure problems are discovered earlier.


Documentation is available on Read The Docs:

a mirror copy is currently available on GitHub pages:

Example usage

>>> from ckan_api_client.high_level import CkanHighlevelClient
>>> from ckan_api_client.objects import CkanDataset

We don’t have datasets yet on our clean instance:

>>> client.list_datasets()

Let’s create a new dataset:

>>> new_dataset = client.create_dataset({
...     'name': 'example-dataset',
...     'title': 'My example dataset'})

>>> new_dataset
CkanDataset({'maintainer': u'', 'name': u'example-dataset', 'author': u'', 'author_email': u'', 'title': 'My example dataset', 'notes': u'', 'owner_org': None, 'private': False, 'maintainer_email': u'', 'url': u'', 'state': u'active', 'extras': {}, 'groups': [], 'license_id': u'', 'type': u'dataset', 'id': u'dfe41b34-5114-47be-8d94-759f942938fc', 'resources': []})

>>> client.list_datasets()

Now, let’s change its title:

>>> new_dataset.title = 'NEW TITLE'

>>> client.update_dataset(new_dataset)
CkanDataset({'maintainer': u'', 'name': u'example-dataset', 'author': u'', 'author_email': u'', 'title': 'NEW TITLE', 'notes': u'', 'owner_org': None, 'private': False, 'maintainer_email': u'', 'url': u'', 'state': u'active', 'extras': {}, 'groups': [], 'license_id': u'', 'type': u'dataset', 'id': u'dfe41b34-5114-47be-8d94-759f942938fc', 'resources': []})

Get it back:

>>> client.get_dataset('dfe41b34-5114-47be-8d94-759f942938fc')
(same result as above)

Delete it:

>>> client.wipe_dataset(

Trying to get the dataset again will raise a “simulated” 404: Ckan will never delete datasets, it just marks them as “state: deleted”, for administrative users, and returns a 403 for anonymous ones. We want to provide more consistency so we raise an exception.

If you really want to get the deleted dataset, add allow_deleted=True.

>>> client.get_dataset('dfe41b34-5114-47be-8d94-759f942938fc')
HTTPError: HTTPError(404, '(logical) dataset state is deleted', original=None)
File Type Py Version Uploaded on Size
ckan-api-client-0.1-beta2.tar.gz (md5) Source 2014-05-16 52KB
  • Downloads (All Versions):
  • 22 downloads in the last day
  • 103 downloads in the last week
  • 224 downloads in the last month