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
- 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
- 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