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='http://master.ckan.org', api_key='')

Bases: object

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

classmethod request(action, data=None, base_url='http://master.ckan.org', api_key='')

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

Code taken from https://gist.github.com/seanh/4130567

See the documentation of the action API, including each of the available actions and the data dicts they accept, here: https://ckan.readthedocs.org/en/255-update-api-docs/api.html

Parameters:
  • 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. “http://datahub.io/
  • api_key (str) – the CKAN API key to put in the ‘Authorization’ header of the HTTP request (optional, default: None)
Returns:

the dictionary returned by the CKAN API encapsulated in a Response object.

Returns:

libckan.model.client.Response

Raises: libckan.model.exceptions.CKANError:
An error occurred accessing CKAN API
class libckan.model.client.Response

Bases: libckan.model.serializable.Serializable

CKAN Action API returns Response objects (in form of JSON). We encapsulate it in a Python object for consistency. The library actually never returns Response objects. It is employed internally.

exceptions Module

libckan custom exceptions are defined in this module.

exception libckan.model.exceptions.CKANError(response_error)

Bases: exceptions.Exception

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

extra Module

class libckan.model.extra.Extra

Bases: libckan.model.serializable.Serializable

Represent extra objects contained in a Package extras array

package Module

This Python package contains the definition of a CKAN Dataset / Package.

class libckan.model.package.Package(name='')

Bases: libckan.model.serializable.Serializable

A CKAN Package of Open Data.

add_extra(extra_obj)

Add an Extra to the Package’s array of extras

Parameters:extra_obj – The Resource to be associated to the Package
Raises:ValueError if extra_obj is not an Extra
add_resource(resource_obj)

Add a Resource to the Package’s array of resources

Parameters:resource_obj – The Resource to be associated to the Package
Raises:ValueError if resource_obj is not a Resource
add_tag(tag_obj)

Add a Tag to the Package’s array of tags

Parameters:tag_obj – The Resource to be associated to the Package
Raises:ValueError if tag_obj is not a Tag
classmethod from_dict(package_dict)

Convert a CKAN JSON Package, already converted to a PYthon dict, to a CKAN Python Package.

Parameters:package_dict – The CKAN Package already converted to a Python dict.
Returns:The resulting CKAN Python Package.
Return type:libckan.models.package.Package
Raises:ValueError if package_dict is not a dict

resource Module

class libckan.model.resource.Resource

Bases: libckan.model.serializable.Serializable

Python CKAN Resource representation

serializable Module

class libckan.model.serializable.Serializable

Bases: object

Superclass for all libckan models related to CKAN API models. A mix between an Abstract Class and an Interface. Never instantiate it.

classmethod from_dict(obj_dict)

Return a CKAN Python object, given the related CKAN dict (converted from CKAN JSON). This method is suitable for all trivial CKAN API objects.

Parameters:obj_dict (dict) – the CKAN Client. Default: an instance of libckan.model.client.Client
Returns:a libckan API Python object.
Return type:libckan.model.serializable.Serializable
Raises:ValueError if obj_dict is not a dict
classmethod to_dict()

tag Module

class libckan.model.tag.Tag

Bases: libckan.model.serializable.Serializable

Tag contained in a Package tags array

trackingsummary Module

class libckan.model.trackingsummary.TrackingSummary

Bases: libckan.model.serializable.Serializable

Tracking Summary object contained in a Package tracking_summary attribute