CKAN Dataset Engine Reference

Last Updated: January 19, 2015

The following reference provides a summary the class used to define the CkanDatasetEngine objects.

class tethys_dataset_services.engines.CkanDatasetEngine(endpoint, apikey=None, username=None, password=None)

Definition for CKAN Dataset Engine objects.

create_dataset(name, console=False, **kwargs)

Create a new CKAN dataset.

Wrapper for the CKAN package_create API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • name (string) -- The id or name of the resource to retrieve.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

create_resource(dataset_id, url=None, file=None, console=False, **kwargs)

Create a new CKAN resource.

Wrapper for the CKAN resource_create API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • dataset_id (string) -- The id or name of the dataset to to which the resource will be added.

  • url (string, optional) -- URL for the resource that will be added to the dataset.

  • file (string, optional) -- Absolute path to a file to upload for the resource.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

delete_dataset(dataset_id, console=False, file=None, **kwargs)

Delete CKAN dataset

Wrapper for the CKAN package_delete API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • dataset_id (string) -- The id or name of the dataset to delete.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

delete_resource(resource_id, console=False, **kwargs)

Delete CKAN resource

Wrapper for the CKAN resource_delete API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • resource_id (string) -- The id of the resource to delete.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

download_dataset(dataset_id, location=None, console=False, **kwargs)

Downloads all resources in a dataset

Description

Parameters:
  • dataset_id (string) -- The id of the dataset to download.

  • location (string, optional) -- Path to the location for the resource to be downloaded. Default is a subdirectory in the current directory named after the dataset. # noqa: E501

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments to pass to the get_dataset method (see CKAN docs).

Returns:

A list of the files that were downloaded.

download_resouce(resource_id, location=None, local_file_name=None, console=False, **kwargs)

Deprecated alias for download_resource method for backwards compatibility (the old method was misspelled).

Description

Parameters:
  • resource_id (string) -- The id of the resource to download.

  • location (string, optional) -- Path to the location for the resource to be downloaded. Defaults to current directory. # noqa: E501

  • local_file_name (string, optional) -- Name for downloaded file.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments to pass to the get_resource method (see CKAN docs).

Returns:

Path and name of the downloaded file.

download_resource(resource_id, location=None, local_file_name=None, console=False, **kwargs)

Download a resource from a resource id

Description

Parameters:
  • resource_id (string) -- The id of the resource to download.

  • location (string, optional) -- Path to the location for the resource to be downloaded. Defaults to current directory. # noqa: E501

  • local_file_name (string, optional) -- Name for downloaded file.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments to pass to the get_resource method (see CKAN docs).

Returns:

Path and name of the downloaded file.

get_dataset(dataset_id, console=False, **kwargs)

Retrieve CKAN dataset

Wrapper for the CKAN package_show API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • dataset_id (string) -- The id or name of the dataset to retrieve.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

get_resource(resource_id, console=False, **kwargs)

Retrieve CKAN resource

Wrapper for the CKAN resource_show API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • resource_id (string) -- The id of the resource to retrieve.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

list_datasets(with_resources=False, console=False, **kwargs)

List CKAN datasets.

Wrapper for the CKAN package_list and current_package_list_with_resources API methods. See the CKAN API docs for these methods to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • with_resources (bool, optional) -- Return a list of dataset dictionaries. Defaults to False.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

A list of dataset names or a list of dataset dictionaries if with_resources is true.

Return type:

list

search_datasets(query=None, filtered_query=None, console=False, **kwargs)

Search CKAN datasets that match a query.

Wrapper for the CKAN search_datasets API method. See the CKAN API docs for this methods to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • query (dict, optional if filtered_query set) -- Key value pairs representing field and values to search for.

  • filtered_query (dict, optional if filtered_query set) -- Key value pairs representing field and values to search for. # noqa: E501

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

search_resources(query, console=False, **kwargs)

Search CKAN resources that match a query.

Wrapper for the CKAN search_resources API method. See the CKAN API docs for this methods to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • query (dict) -- Key value pairs representing field and values to search for.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

property type

CKAN Dataset Engine Type

update_dataset(dataset_id, console=False, **kwargs)

Update CKAN dataset

Wrapper for the CKAN package_update API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • dataset_id (string) -- The id or name of the dataset to update.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

update_resource(resource_id, url=None, file=None, console=False, **kwargs)

Update CKAN resource

Wrapper for the CKAN resource_update API method. See the CKAN API docs for this method to see applicable options (http://docs.ckan.org/en/ckan-2.2/api.html).

Parameters:
  • resource_id (string) -- The id of the resource that will be updated.

  • url (string, optional) -- URL of the resource that will be added to the dataset.

  • file (string, optional) -- Absolute path to a file to upload for the resource.

  • console (bool, optional) -- Pretty print the result to the console for debugging. Defaults to False.

  • **kwargs -- Any number of optional keyword arguments for the method (see CKAN docs).

Returns:

The response dictionary or None if an error occurs.

validate()

Validate CKAN dataset engine. Will throw an error if not valid.