High-level

class ckan_api_client.high_level.CkanHighlevelClient(base_url, api_key=None)[source]

High-level client, handling CRUD of objects.

This class only returns / handles CkanObjects, to make sure we are handling consistent data (they have validators in place)

list_datasets()[source]
Returns:a list of dataset ids
iter_datasets()[source]

Generator, iterating over all the datasets in ckan

get_dataset(id, allow_deleted=False)[source]

Get a specific dataset, by id

Note

Since the Ckan API use both ids and names as keys, both get_dataset() and get_dataset_by_name() will perform the exact same request in the background.

The difference is only in the high-level handling: the function will check whether the expected id has the correct value, and raise an HTTPError(404, ..) otherwise..

Parameters:
  • id (str) – the dataset id
  • allow_deleted – Whether to return even logically deleted objects. If set to False (the default) will raise a HTTPError(404, ..) if state != 'active'
Return type:

CkanDataset

get_dataset_by_name(name, allow_deleted=False)[source]

Get a specific dataset, by name

Note

See note on get_dataset()

Parameters:
  • name (str) – the dataset name
  • allow_deleted – Whether to return even logically deleted objects. If set to False (the default) will raise a HTTPError(404, ..) if state != 'active'
Return type:

CkanDataset

save_dataset(dataset)[source]

If the dataset already has an id, call update_dataset(), otherwise, call create_dataset().

Returns:as returned by the called function.
Return type:CkanDataset
create_dataset(dataset)[source]

Create a dataset

Return type:CkanDataset
update_dataset(dataset)[source]

Update a dataset

Return type:CkanDataset
delete_dataset(id)[source]

Delete a dataset, by id

wipe_dataset(id)[source]

Actually delete a dataset, by renaming it first

list_organizations()[source]
list_organization_names()[source]
iter_organizations()[source]
get_organization(id, allow_deleted=False)[source]

Get organization, by id.

Note

See note on get_dataset()

Parameters:
  • id (str) – the organization id
  • allow_deleted – Whether to return even logically deleted objects. If set to False (the default) will raise a HTTPError(404, ..) if state != 'active'
Return type:

CkanOrganization

get_organization_by_name(name, allow_deleted=False)[source]

Get organization by name.

Note

See note on get_dataset()

Parameters:
  • name (str) – the organization name
  • allow_deleted – Whether to return even logically deleted objects. If set to False (the default) will raise a HTTPError(404, ..) if state != 'active'
Return type:

CkanOrganization

save_organization(organization)[source]
create_organization(organization)[source]

Create an organization

Return type:CkanOrganization
update_organization(organization)[source]
Return type:CkanOrganization
delete_organization(id)[source]
list_groups()[source]
list_group_names()[source]
iter_groups()[source]
get_group(id, allow_deleted=False)[source]

Get group, by id.

Note

See note on get_dataset()

Parameters:
  • id (str) – the group id
  • allow_deleted – Whether to return even logically deleted objects. If set to False (the default) will raise a HTTPError(404, ..) if state != 'active'
Return type:

CkanGroup

get_group_by_name(name, allow_deleted=False)[source]

Get group by name.

Note

See note on get_dataset()

Parameters:
  • name (str) – the group name
  • allow_deleted – Whether to return even logically deleted objects. If set to False (the default) will raise a HTTPError(404, ..) if state != 'active'
Return type:

CkanGroup

save_group(group)[source]
create_group(group)[source]
Return type:CkanGroup
update_group(group)[source]
Return type:CkanGroup
delete_group(id)[source]