model Package

model Package

Implementation of CKAN API Models takes place here.

client Module

Lowest communication layer of libckan. This package contains a wrapper for urllib2 requests that communicates with CKAN Api. It also contains a Response class to represent CKAN responses.

class libckan.model.client.Client(base_url='', api_key='')

Bases: object

CKAN API Client. It does HTTP POST request to CKAN API.

classmethod request(action, data=None, base_url='', api_key='')

Post a data dict to one of the actions of the CKAN action API.

Code adapted from

  • action (str) – the action to post to, e.g. “package_create”
  • data (dict) – the data to post (optional, default: {})
  • base_url (str) – the base URL of the CKAN instance to post to, e.g. “
  • api_key (str) – the CKAN API key to put in the ‘Authorization’ header of the HTTP request (optional, default: ‘’)

the dictionary returned by the CKAN API



Raises: libckan.model.exceptions.CKANError:
An error occurred accessing CKAN API
classmethod sanitize_params(params)

Polishes the parameters to be sent to CKAN.

Parameters:params – A dict of parameters. Usually obtained with a call

to locals() :type client: dict

Returns:The sanitizied dict of parameters
Return type:dict

exceptions Module

libckan custom exceptions are defined in this module.

exception libckan.model.exceptions.CKANAccessError(response_error)

Bases: libckan.model.exceptions.CKANError

Errors related to authentication (i.e., access denied)

exception libckan.model.exceptions.CKANError(response_error)

Bases: exceptions.Exception

General CKAN API error. It encapsulates the error part of a CKAN Response.

exception libckan.model.exceptions.CKANValidationError(response_error)

Bases: libckan.model.exceptions.CKANError

Errors related to Validation issues.