hdx.data.showcase
module hdx.data.showcase
Showcase class containing all logic for creating, checking, and updating showcases.
Classes
-
Showcase — Showcase class containing all logic for creating, checking, and updating showcases.
class Showcase(initial_data: dict | None = None, configuration: Configuration | None = None)
Bases : HDXObject
Showcase class containing all logic for creating, checking, and updating showcases.
Parameters
-
initial_data : dict | None — Initial showcase metadata dictionary. Defaults to None.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Methods
-
actions — Dictionary of actions that can be performed on object
-
update_from_yaml — Update showcase metadata with static metadata from YAML file
-
update_from_json — Update showcase metadata with static metadata from JSON file
-
read_from_hdx — Reads the showcase given by identifier from HDX and returns Showcase object
-
check_required_fields — 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.
-
update_in_hdx — Check if showcase exists in HDX and if so, update it
-
create_in_hdx — Check if showcase exists in HDX and if so, update it, otherwise create it
-
delete_from_hdx — Deletes a showcase from HDX.
-
get_tags — Return the dataset's list of tags
-
add_tag — Add a tag
-
add_tags — Add a list of tags
-
clean_tags — Clean tags in an HDX object according to tags cleanup spreadsheet
-
remove_tag — Remove a tag
-
get_datasets — Get any datasets in the showcase
-
add_dataset — Add a dataset
-
add_datasets — Add multiple datasets
-
remove_dataset — Remove a dataset
-
search_in_hdx — Searches for datasets in HDX
-
get_all_showcases — Get all showcases in HDX
staticmethod Showcase.actions() → dict[str, str]
Dictionary of actions that can be performed on object
Returns
-
dict[str, str] — Dictionary of actions that can be performed on object
method Showcase.update_from_yaml(path: Path | str = Path('config', 'hdx_showcase_static.yaml')) → None
Update showcase metadata with static metadata from YAML file
Parameters
-
path : Path | str — Path to YAML dataset metadata. Defaults to config/hdx_showcase_static.yaml.
Returns
-
None — None
method Showcase.update_from_json(path: Path | str = Path('config', 'hdx_showcase_static.json')) → None
Update showcase metadata with static metadata from JSON file
Parameters
-
path : Path | str — Path to JSON dataset metadata. Defaults to config/hdx_showcase_static.json.
Returns
-
None — None
classmethod Showcase.read_from_hdx(identifier: str, configuration: Configuration | None = None) → Optional['Showcase']
Reads the showcase given by identifier from HDX and returns Showcase object
Parameters
-
identifier : str — Identifier of showcase
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
Optional['Showcase'] — Showcase object if successful read, None if not
method Showcase.check_required_fields(ignore_fields: Sequence[str] = ()) → None
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.
Parameters
-
ignore_fields : Sequence[str] — Fields to ignore. Default is ().
Returns
-
None — None
method Showcase.update_in_hdx(**kwargs: Any) → None
Check if showcase exists in HDX and if so, update it
Returns
-
None — None
method Showcase.create_in_hdx(**kwargs: Any) → None
Check if showcase exists in HDX and if so, update it, otherwise create it
Returns
-
None — None
method Showcase.delete_from_hdx() → None
Deletes a showcase from HDX.
Returns
-
None — None
method Showcase.get_tags() → list[str]
Return the dataset's list of tags
Returns
-
list[str] — List of tags or [] if there are none
method Showcase.add_tag(tag: str, log_deleted: bool = True) → tuple[list[str], list[str]]
Add a tag
Parameters
-
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
method Showcase.add_tags(tags: Sequence[str], log_deleted: bool = True) → tuple[list[str], list[str]]
Add a list of tags
Parameters
-
tags : Sequence[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
method Showcase.clean_tags(log_deleted: bool = True) → tuple[list[str], list[str]]
Clean tags in an HDX object according to tags cleanup spreadsheet
Parameters
-
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
method Showcase.remove_tag(tag: str) → bool
Remove a tag
Parameters
-
tag : str — Tag to remove
Returns
-
bool — True if tag removed or False if not
method Showcase.get_datasets() → list['Dataset']
Get any datasets in the showcase
Returns
-
list['Dataset'] — List of datasets
method Showcase.add_dataset(dataset: Union['Dataset', dict, str], datasets_to_check: Sequence['Dataset'] = None) → bool
Add a dataset
Parameters
-
dataset : Union['Dataset', dict, str] — Either a dataset id or dataset metadata either from a Dataset object or a dictionary
-
datasets_to_check : Sequence['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
method Showcase.add_datasets(datasets: Sequence[Union['Dataset', dict, str]], datasets_to_check: Sequence['Dataset'] = None) → bool
Add multiple datasets
Parameters
-
datasets : Sequence[Union['Dataset', dict, str]] — A list of either dataset ids or dataset metadata from Dataset objects or dictionaries
-
datasets_to_check : Sequence['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
method Showcase.remove_dataset(dataset: Union['Dataset', dict, str]) → None
Remove a dataset
Parameters
-
dataset : Union['Dataset', dict, str] — Either a dataset id or dataset metadata either from a Dataset object or a dictionary
Returns
-
None — None
classmethod Showcase.search_in_hdx(query: str | None = ':', configuration: Configuration | None = None, page_size: int = 1000, **kwargs: Any) → list['Showcase']
Searches for datasets in HDX
Parameters
-
query : str | None — Query (in Solr format). Defaults to ':'.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
-
page_size : int — Size of page to return. Defaults to 1000.
-
**kwargs : Any — 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['Showcase'] — list of datasets resulting from query
classmethod Showcase.get_all_showcases(configuration: Configuration | None = None, page_size: int = 1000, **kwargs: Any) → list['Showcase']
Get all showcases in HDX
Parameters
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
-
page_size : int — Size of page to return. Defaults to 1000.
-
**kwargs : Any — 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