Skip to content

hdx.data.showcase

Showcase class containing all logic for creating, checking, and updating showcases.

Showcase Objects

class Showcase(HDXObject)

[view_source]

Showcase class containing all logic for creating, checking, and updating showcases.

Arguments:

  • initial_data Optional[Dict] - Initial showcase metadata dictionary. Defaults to None.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

actions

@staticmethod
def actions() -> Dict[str, str]

[view_source]

Dictionary of actions that can be performed on object

Returns:

Dict[str, str]: Dictionary of actions that can be performed on object

update_from_yaml

def update_from_yaml(path: str = join("config",
                                      "hdx_showcase_static.yaml")) -> None

[view_source]

Update showcase metadata with static metadata from YAML file

Arguments:

  • path Optional[str] - Path to YAML dataset metadata. Defaults to config/hdx_showcase_static.yaml.

Returns:

None

update_from_json

def update_from_json(path: str = join("config",
                                      "hdx_showcase_static.json")) -> None

[view_source]

Update showcase metadata with static metadata from JSON file

Arguments:

  • path Optional[str] - Path to JSON dataset metadata. Defaults to config/hdx_showcase_static.json.

Returns:

None

read_from_hdx

@classmethod
def read_from_hdx(
        cls,
        identifier: str,
        configuration: Optional[Configuration] = None) -> Optional["Showcase"]

[view_source]

Reads the showcase given by identifier from HDX and returns Showcase object

Arguments:

  • identifier str - Identifier of showcase
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.

Returns:

  • Optional[Showcase] - Showcase object if successful read, None if not

check_required_fields

def check_required_fields(ignore_fields: ListTuple[str] = tuple()) -> None

[view_source]

Check that metadata for showcase is complete. The parameter ignore_fields should be set if required to any fields that should be ignored for the particular operation.

Arguments:

  • ignore_fields ListTuple[str] - Fields to ignore. Default is tuple().

Returns:

None

update_in_hdx

def update_in_hdx(**kwargs: Any) -> None

[view_source]

Check if showcase exists in HDX and if so, update it

Returns:

None

create_in_hdx

def create_in_hdx(**kwargs: Any) -> None

[view_source]

Check if showcase exists in HDX and if so, update it, otherwise create it

Returns:

None

delete_from_hdx

def delete_from_hdx() -> None

[view_source]

Deletes a showcase from HDX.

Returns:

None

get_tags

def get_tags() -> List[str]

[view_source]

Return the dataset's list of tags

Returns:

  • List[str] - List of tags or [] if there are none

add_tag

def add_tag(tag: str, log_deleted: bool = True) -> Tuple[List[str], List[str]]

[view_source]

Add a tag

Arguments:

  • tag str - Tag to add
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of added tags and list of deleted tags and tags not added

add_tags

def add_tags(tags: ListTuple[str],
             log_deleted: bool = True) -> Tuple[List[str], List[str]]

[view_source]

Add a list of tags

Arguments:

  • tags ListTuple[str] - List of tags to add
  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of added tags and list of deleted tags and tags not added

clean_tags

def clean_tags(log_deleted: bool = True) -> Tuple[List[str], List[str]]

[view_source]

Clean tags in an HDX object according to tags cleanup spreadsheet

Arguments:

  • log_deleted bool - Whether to log informational messages about deleted tags. Defaults to True.

Returns:

Tuple[List[str], List[str]]: Tuple containing list of mapped tags and list of deleted tags and tags not added

remove_tag

def remove_tag(tag: str) -> bool

[view_source]

Remove a tag

Arguments:

  • tag str - Tag to remove

Returns:

  • bool - True if tag removed or False if not

get_datasets

def get_datasets() -> List["Dataset"]

[view_source]

Get any datasets in the showcase

Returns:

  • List[Dataset] - List of datasets

add_dataset

def add_dataset(dataset: Union["Dataset", Dict, str],
                datasets_to_check: ListTuple["Dataset"] = None) -> bool

[view_source]

Add a dataset

Arguments:

  • dataset Union[Dataset,Dict,str] - Either a dataset id or dataset metadata either from a Dataset object or a dictionary
  • datasets_to_check ListTuple[Dataset] - List of datasets against which to check existence of dataset. Defaults to datasets in showcase.

Returns:

  • bool - True if the dataset was added, False if already present

add_datasets

def add_datasets(datasets: ListTuple[Union["Dataset", Dict, str]],
                 datasets_to_check: ListTuple["Dataset"] = None) -> bool

[view_source]

Add multiple datasets

Arguments:

  • datasets ListTuple[Union[Dataset,Dict,str]] - A list of either dataset ids or dataset metadata from Dataset objects or dictionaries
  • datasets_to_check ListTuple[Dataset] - List of datasets against which to check existence of dataset. Defaults to datasets in showcase.

Returns:

  • bool - True if all datasets added or False if any already present

remove_dataset

def remove_dataset(dataset: Union["Dataset", Dict, str]) -> None

[view_source]

Remove a dataset

Arguments:

  • dataset Union[Dataset,Dict,str] - Either a dataset id or dataset metadata either from a Dataset object or a dictionary

Returns:

None

search_in_hdx

@classmethod
def search_in_hdx(cls,
                  query: Optional[str] = "*:*",
                  configuration: Optional[Configuration] = None,
                  page_size: int = 1000,
                  **kwargs: Any) -> List["Showcase"]

[view_source]

Searches for datasets in HDX

Arguments:

  • query Optional[str] - Query (in Solr format). Defaults to ':'.
  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.
  • page_size int - Size of page to return. Defaults to 1000.
  • **kwargs - See below
  • fq string - Any filter queries to apply
  • sort string - Sorting of the search results. Defaults to 'relevance asc, metadata_modified desc'.
  • rows int - Number of matching rows to return. Defaults to all datasets (sys.maxsize).
  • start int - Offset in the complete result for where the set of returned datasets should begin
  • facet string - Whether to enable faceted results. Default to True.
  • facet.mincount int - Minimum counts for facet fields should be included in the results
  • facet.limit int - Maximum number of values the facet fields return (- = unlimited). Defaults to 50.
  • facet.field List[str] - Fields to facet upon. Default is empty.
  • use_default_schema bool - Use default package schema instead of custom schema. Defaults to False.

Returns:

  • List[Dataset] - list of datasets resulting from query

get_all_showcases

@classmethod
def get_all_showcases(cls,
                      configuration: Optional[Configuration] = None,
                      page_size: int = 1000,
                      **kwargs: Any) -> List["Showcase"]

[view_source]

Get all showcases in HDX

Arguments:

  • configuration Optional[Configuration] - HDX configuration. Defaults to global configuration.
  • page_size int - Size of page to return. Defaults to 1000.
  • **kwargs - See below
  • rows int - Number of rows to return. Defaults to all showcases (sys.maxsize)
  • start int - Offset in the complete result for where the set of returned showcases should begin

Returns:

  • List[Showcase] - list of all showcases in HDX