hdx.api.locations
module hdx.api.locations
class Locations()
Methods to help with countries and continents
Methods
-
validlocations — Read valid locations from HDX
-
set_validlocations — Set valid locations using list of dictionaries of form {'name': 'zmb', 'title', 'Zambia'}
-
get_location_from_HDX_code — Get location from HDX location code
-
get_HDX_code_from_location — Get HDX code for location
-
get_HDX_code_from_location_partial — Get HDX code for location
classmethod Locations.validlocations(configuration=None) → list[dict]
Read valid locations from HDX
Parameters
-
configuration — HDX configuration. Defaults to global configuration.
Returns
-
list[dict] — A list of valid locations
classmethod Locations.set_validlocations(locations: Sequence[dict]) → None
Set valid locations using list of dictionaries of form {'name': 'zmb', 'title', 'Zambia'}
Parameters
-
locations : Sequence[dict] — List of dictionaries of form {'name': 'zmb', 'title', 'Zambia'}
Returns
-
None — None
classmethod Locations.get_location_from_HDX_code(code: str, locations: Sequence[dict] | None = None, configuration: Configuration | None = None) → str | None
Get location from HDX location code
Parameters
-
code : str — code for which to get location name
-
locations : Sequence[dict] | None — Valid locations list. Defaults to list downloaded from HDX.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
str | None — location name or None
classmethod Locations.get_HDX_code_from_location(location: str, locations: Sequence[dict] | None = None, configuration: Configuration | None = None) → str | None
Get HDX code for location
Parameters
-
location : str — Location for which to get HDX code
-
locations : Sequence[dict] | None — Valid locations list. Defaults to list downloaded from HDX.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
str | None — HDX code or None
classmethod Locations.get_HDX_code_from_location_partial(location: str, locations: Sequence[dict] | None = None, configuration: Configuration | None = None) → tuple[str | None, bool]
Get HDX code for location
Parameters
-
location : str — Location for which to get HDX code
-
locations : Sequence[dict] | None — Valid locations list. Defaults to list downloaded from HDX.
-
configuration : Configuration | None — HDX configuration. Defaults to global configuration.
Returns
-
tuple[str | None, bool] — HDX code and if the match is exact or (None, False) for no match