High-level¶
- class ckan_api_client.high_level.CkanHighlevelClient(base_url, api_key=None, fail_on_inconsistency=False)[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)
Parameters: - base_url – Base URL for the Ckan instance.
- api_key – API key to be used when accessing Ckan. This is required for writing.
- fail_on_inconsistency – Whether to fail on “inconsistencies” (mismatching updated objects). This is especially useful during development, in order to catch many problems with the client itself (or new bugs 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:
- 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:
- 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
- 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:
- 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:
- create_organization(organization)[source]¶
Create an organization
Return type: CkanOrganization
- update_organization(organization)[source]¶
Return type: CkanOrganization
- 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:
- 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: