Low-level

This is the client providing the lowest level of abstraction.

class ckan_api_client.low_level.CkanLowlevelClient(base_url, api_key=None)[source]

Ckan low-level client.

  • Handles authentication and response validation
  • Handles request body serialization and response body deserialization
  • Raises HTTPError exceptions on failed HTTP requests
  • Performs some checks on return values from the API
anonymous[source]

Property, returning a copy of this client, without an api_key set

request(method, path, **kwargs)[source]

Wrapper around requests.request().

Extra functionality provided:

  • Add Authorization header to requests
  • If data is an object, serialize it with json and add the Content-type: application/json header.
  • If the response didn’t contain an “ok” code, raises a HTTPError exception.
Parameters:
  • method – HTTP method to be used
  • path – Path, relative to the Ckan root. For example: /api/3/action/package_list
  • headers – HTTP headers to be added to the request
  • data – Data to be sent in the request body
  • kwargs – Extra keyword arguments will be passed directly to the requests.request() call.
Raises ckan_api_client.exceptions.HTTPError:
 

in case the HTTP request returned a non-ok status code

Returns:

a requests response object

list_datasets()[source]

Return a list of all dataset ids

iter_datasets()[source]

Generator yielding dataset objects, iterating over the whole database.

get_dataset(dataset_id)[source]

Get a dataset, using API v2

Parameters:dataset_id – ID of the requested dataset
Returns:a dict containing the data as returned from the API
Return type:dict
post_dataset(dataset)[source]

POST a dataset, using API v2 (usually for creation)

Parameters:dataset (dict) – a dict containing data to be sent to Ckan. Should not already contain an id
Returns:a dict containing the data as returned from the API
Return type:dict
put_dataset(dataset)[source]

PUT a dataset, using API v2 (usually for update)

Parameters:dataset (dict) – a dict containing data to be sent to Ckan. Must contain an id, that will be used to build the URL
Returns:a dict containing the updated dataset as returned from the API
Return type:dict
delete_dataset(dataset_id, ignore_404=True)[source]

DELETE a dataset, using API v2

Parameters:
  • dataset_id – if of the dataset to be deleted
  • ignore_404 (bool) – if True (the default), will simply ignore http 404 errors from the API
list_groups()[source]
iter_groups()[source]
get_group(group_id)[source]
post_group(group)[source]
put_group(group)[source]
delete_group(group_id, ignore_404=True)[source]
list_organizations()[source]
iter_organizations()[source]
get_organization(id)[source]
post_organization(organization)[source]
put_organization(organization)[source]

Warning! with api v3 we need to use POST!

delete_organization(id, ignore_404=True)[source]
list_licenses()[source]