hdx.api.configuration
Configuration for HDX
Configuration Objects
class Configuration(UserDict)
Configuration for HDX
Arguments:
**kwargs
- See belowuser_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.yaml.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 ORhdx_config_json
str - Path to JSON HDX configuration ORhdx_config_yaml
str - Path to YAML HDX configurationproject_config_dict
dict - Project configuration dictionary ORproject_config_json
str - Path to JSON Project configuration ORproject_config_yaml
str - Path to YAML Project configurationhdx_base_config_dict
dict - HDX base configuration dictionary ORhdx_base_config_json
str - Path to JSON HDX base configuration ORhdx_base_config_yaml
str - Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml.
set_read_only
def set_read_only(read_only: bool = True) -> None
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
Set HDX api key
Arguments:
apikey
str - Value to set api key.
Returns:
None
get_api_key
def get_api_key() -> Optional[str]
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
Return user agent
Returns:
str
- User agent
get_hdx_site_url
def get_hdx_site_url() -> str
Return HDX web site url
Returns:
str
- HDX web site url
get_dataset_url
def get_dataset_url(name: str) -> str
Return HDX dataset url given dataset name
Arguments:
name
- Dataset name
Returns:
str
- HDX dataset url
get_session
def get_session() -> requests.Session
Return the session object
Returns:
requests.Session
- The session object
remoteckan
def remoteckan() -> ckanapi.RemoteCKAN
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
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]
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.yaml.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
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
Return the Email object (see :any:Email
)
Returns:
Email
- The email object
setup_emailer
def setup_emailer(**kwargs: Any) -> None
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 belowemail_config_dict
dict - HDX configuration dictionary ORemail_config_json
str - Path to JSON HDX configuration ORemail_config_yaml
str - Path to YAML HDX configuration. Defaults to ~/hdx_email_configuration.yaml.
Returns:
None
read
@classmethod
def read(cls) -> "Configuration"
Read the HDX configuration
Returns:
Configuration
- The HDX configuration
setup
@classmethod
def setup(cls,
configuration: Optional["Configuration"] = None,
**kwargs: Any) -> None
Construct the HDX configuration
Arguments:
configuration
Optional[Configuration] - Configuration instance. Defaults to setting one up from passed arguments.**kwargs
- See belowuser_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.yaml.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 ORhdx_config_json
str - Path to JSON HDX configuration ORhdx_config_yaml
str - Path to YAML HDX configurationproject_config_dict
dict - Project configuration dictionary ORproject_config_json
str - Path to JSON Project configuration ORproject_config_yaml
str - Path to YAML Project configurationhdx_base_config_dict
dict - HDX base configuration dictionary ORhdx_base_config_json
str - Path to JSON HDX base configuration ORhdx_base_config_yaml
str - Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml.
Returns:
None
create
@classmethod
def create(cls,
configuration: Optional["Configuration"] = None,
remoteckan: Optional[ckanapi.RemoteCKAN] = None,
**kwargs: Any) -> str
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 belowuser_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.yaml.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 ORhdx_config_json
str - Path to JSON HDX configuration ORhdx_config_yaml
str - Path to YAML HDX configurationproject_config_dict
dict - Project configuration dictionary ORproject_config_json
str - Path to JSON Project configuration ORproject_config_yaml
str - Path to YAML Project configurationhdx_base_config_dict
dict - HDX base configuration dictionary ORhdx_base_config_json
str - Path to JSON HDX base configuration ORhdx_base_config_yaml
str - Path to YAML HDX base configuration. Defaults to library's internal hdx_base_configuration.yaml.
Returns:
str
- HDX site url
delete
@classmethod
def delete(cls) -> None
Delete global HDX configuration.
Returns:
None