hdx.api.configuration

[view_source]

Configuration for HDX

Configuration Objects

class Configuration(UserDict)

[view_source]

Configuration for HDX

Arguments:

  • **kwargs - See below
  • user_agent str - User agent string. HDXPythonLibrary/X.X.X- is prefixed. Must be supplied if remoteckan is not.
  • user_agent_config_yaml str - Path to YAML user agent configuration. Ignored if user_agent supplied. Defaults to ~/.useragent.yml.
  • user_agent_lookup str - Lookup key for YAML. Ignored if user_agent supplied.
  • hdx_url str - HDX url to use. Overrides hdx_site.
  • hdx_site str - HDX site to use eg. prod, test.
  • hdx_read_only bool - Whether to access HDX in read only mode. Defaults to False.
  • hdx_key str - Your HDX key. Ignored if hdx_read_only = True.
  • hdx_config_dict dict - HDX configuration dictionary to use instead of above 3 parameters OR
  • hdx_config_json str - Path to JSON HDX configuration OR
  • hdx_config_yaml str - Path to YAML HDX configuration
  • project_config_dict dict - Project configuration dictionary OR
  • project_config_json str - Path to JSON Project configuration OR
  • project_config_yaml str - Path to YAML Project configuration
  • hdx_base_config_dict dict - HDX base configuration dictionary OR
  • hdx_base_config_json str - Path to JSON HDX base configuration OR
  • hdx_base_config_yaml str - Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yml.

set_read_only

def set_read_only(read_only: bool = True) -> None

[view_source]

Set HDX read only flag

Arguments:

  • read_only bool - Value to set HDX read only flag. Defaults to True.

Returns:

None

set_api_key

def set_api_key(apikey: str) -> None

[view_source]

Set HDX api key

Arguments:

  • apikey str - Value to set api key.

Returns:

None

get_api_key

def get_api_key() -> Optional[str]

[view_source]

Return HDX api key or None if read only

Returns:

  • Optional[str] - HDX api key or None if read only

get_user_agent

def get_user_agent() -> str

[view_source]

Return user agent

Returns:

  • str - User agent

get_hdx_site_url

def get_hdx_site_url() -> str

[view_source]

Return HDX web site url

Returns:

  • str - HDX web site url

get_dataset_url

def get_dataset_url(name: str) -> str

[view_source]

Return HDX dataset url given dataset name

Arguments:

  • name - Dataset name

Returns:

  • str - HDX dataset url

get_session

def get_session() -> requests.Session

[view_source]

Return the session object

Returns:

  • requests.Session - The session object

remoteckan

def remoteckan() -> ckanapi.RemoteCKAN

[view_source]

Return the remote CKAN object (see ckanapi library)

Returns:

  • ckanapi.RemoteCKAN - The remote CKAN object

call_remoteckan

def call_remoteckan(*args: Any, **kwargs: Any) -> Dict

[view_source]

Calls the remote CKAN

Arguments:

  • *args - Arguments to pass to remote CKAN call_action method
  • **kwargs - Keyword arguments to pass to remote CKAN call_action method

Returns:

  • Dict - The response from the remote CKAN call_action method

create_session_user_agent

@classmethod
def create_session_user_agent(cls, session: requests.Session = None, user_agent: Optional[str] = None, user_agent_config_yaml: Optional[str] = None, user_agent_lookup: Optional[str] = None, use_env: bool = False, **kwargs: Any, ,) -> Tuple[requests.Session, str]

[view_source]

Create session and user agent from configuration

Arguments:

  • session requests.Session - requests Session object to use. Defaults to calling hdx.utilities.session.get_session()
  • user_agent Optional[str] - User agent string. HDXPythonLibrary/X.X.X- is prefixed.
  • user_agent_config_yaml Optional[str] - Path to YAML user agent configuration. Ignored if user_agent supplied. Defaults to ~/.useragent.yml.
  • user_agent_lookup Optional[str] - Lookup key for YAML. Ignored if user_agent supplied.
  • use_env bool - Whether to read environment variables. Defaults to False.

Returns:

Tuple[requests.Session, str]: Tuple of (session, user agent)

setup_session_remoteckan

def setup_session_remoteckan(remoteckan: Optional[ckanapi.RemoteCKAN] = None, **kwargs: Any) -> None

[view_source]

Set up remote CKAN from provided CKAN or by creating from configuration

Arguments:

  • remoteckan Optional[ckanapi.RemoteCKAN] - CKAN instance. Defaults to setting one up from configuration.

Returns:

None

emailer

def emailer() -> Email

[view_source]

Return the Email object (see :any:Email)

Returns:

  • Email - The email object

setup_emailer

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

[view_source]

Set up emailer. Parameters in dictionary or file (eg. yaml below): | connection_type: "ssl" ("ssl" for smtp ssl or "lmtp", otherwise basic smtp is assumed) | host: "localhost" | port: 123 | local_hostname: "mycomputer.fqdn.com" | timeout: 3 | username: "user" | password: "pass"

Arguments:

  • **kwargs - See below
  • email_config_dict dict - HDX configuration dictionary OR
  • email_config_json str - Path to JSON HDX configuration OR
  • email_config_yaml str - Path to YAML HDX configuration. Defaults to ~/hdx_email_configuration.yml.

Returns:

None

read

@classmethod
def read(cls) -> "Configuration"

[view_source]

Read the HDX configuration

Returns:

  • Configuration - The HDX configuration

setup

@classmethod
def setup(cls, configuration: Optional["Configuration"] = None, **kwargs: Any) -> None

[view_source]

Construct the HDX configuration

Arguments:

  • configuration Optional[Configuration] - Configuration instance. Defaults to setting one up from passed arguments.
  • **kwargs - See below
  • user_agent str - User agent string. HDXPythonLibrary/X.X.X- is prefixed. Must be supplied if remoteckan is not.
  • user_agent_config_yaml str - Path to YAML user agent configuration. Ignored if user_agent supplied. Defaults to ~/.useragent.yml.
  • user_agent_lookup str - Lookup key for YAML. Ignored if user_agent supplied.
  • hdx_url str - HDX url to use. Overrides hdx_site.
  • hdx_site str - HDX site to use eg. prod, test.
  • hdx_read_only bool - Whether to access HDX in read only mode. Defaults to False.
  • hdx_key str - Your HDX key. Ignored if hdx_read_only = True.
  • hdx_config_dict dict - HDX configuration dictionary to use instead of above 3 parameters OR
  • hdx_config_json str - Path to JSON HDX configuration OR
  • hdx_config_yaml str - Path to YAML HDX configuration
  • project_config_dict dict - Project configuration dictionary OR
  • project_config_json str - Path to JSON Project configuration OR
  • project_config_yaml str - Path to YAML Project configuration
  • hdx_base_config_dict dict - HDX base configuration dictionary OR
  • hdx_base_config_json str - Path to JSON HDX base configuration OR
  • hdx_base_config_yaml str - Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yml.

Returns:

None

create

@classmethod
def create(cls, configuration: Optional["Configuration"] = None, remoteckan: Optional[ckanapi.RemoteCKAN] = None, **kwargs: Any, ,) -> str

[view_source]

Create HDX configuration. Can only be called once (will raise an error if called more than once).

Arguments:

  • configuration Optional[Configuration] - Configuration instance. Defaults to setting one up from passed arguments.
  • remoteckan Optional[ckanapi.RemoteCKAN] - CKAN instance. Defaults to setting one up from configuration.
  • **kwargs - See below
  • user_agent str - User agent string. HDXPythonLibrary/X.X.X- is prefixed. Must be supplied if remoteckan is not.
  • user_agent_config_yaml str - Path to YAML user agent configuration. Ignored if user_agent supplied. Defaults to ~/.useragent.yml.
  • user_agent_lookup str - Lookup key for YAML. Ignored if user_agent supplied.
  • hdx_url str - HDX url to use. Overrides hdx_site.
  • hdx_site str - HDX site to use eg. prod, test.
  • hdx_read_only bool - Whether to access HDX in read only mode. Defaults to False.
  • hdx_key str - Your HDX key. Ignored if hdx_read_only = True.
  • hdx_config_dict dict - HDX configuration dictionary to use instead of above 3 parameters OR
  • hdx_config_json str - Path to JSON HDX configuration OR
  • hdx_config_yaml str - Path to YAML HDX configuration
  • project_config_dict dict - Project configuration dictionary OR
  • project_config_json str - Path to JSON Project configuration OR
  • project_config_yaml str - Path to YAML Project configuration
  • hdx_base_config_dict dict - HDX base configuration dictionary OR
  • hdx_base_config_json str - Path to JSON HDX base configuration OR
  • hdx_base_config_yaml str - Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yml.

Returns:

  • str - HDX site url

delete

@classmethod
def delete(cls) -> None

[view_source]

Delete global HDX configuration.

Returns:

None