hdx.data.showcase
Showcase class containing all logic for creating, checking, and updating showcases.
Showcase Objects
class Showcase(HDXObject)
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]
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
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
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"]
Reads the showcase given by identifier from HDX and returns Showcase object
Arguments:
identifier
str - Identifier of showcaseconfiguration
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
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
Check if showcase exists in HDX and if so, update it
Returns:
None
create_in_hdx
def create_in_hdx(**kwargs: Any) -> None
Check if showcase exists in HDX and if so, update it, otherwise create it
Returns:
None
delete_from_hdx
def delete_from_hdx() -> None
Deletes a showcase from HDX.
Returns:
None
get_tags
def get_tags() -> List[str]
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]]
Add a tag
Arguments:
tag
str - Tag to addlog_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]]
Add a list of tags
Arguments:
tags
ListTuple[str] - List of tags to addlog_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]]
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
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"]
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
Add a dataset
Arguments:
dataset
Union[Dataset,Dict,str] - Either a dataset id or dataset metadata either from a Dataset object or a dictionarydatasets_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
Add multiple datasets
Arguments:
datasets
ListTuple[Union[Dataset,Dict,str]] - A list of either dataset ids or dataset metadata from Dataset objects or dictionariesdatasets_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
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"]
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 belowfq
string - Any filter queries to applysort
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 beginfacet
string - Whether to enable faceted results. Default to True.facet.mincount
int - Minimum counts for facet fields should be included in the resultsfacet.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"]
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 belowrows
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