HDX Python Utilities
Project description
The HDX Python Utilities Library provides a range of helpful utilities:
Easy downloading of files with support for authentication, streaming and hashing
Simple emailing
Easy logging setup
Dictionary and list utilities
Text block matching
Path utilities
Loading and saving JSON and YAML (inc. OrderedDict)
This library is part of the Humanitarian Data Exchange (HDX) project. If you have humanitarian related data, please upload your datasets to HDX.
Usage
The library has detailed API documentation which can be found here: http://ocha-dap.github.io/hdx-python-utilities/. The code for the library is here: https://github.com/ocha-dap/hdx-python-utilities.
Configuring Logging
The library provides coloured logs with a simple default setup. If you wish to change the logging configuration from the defaults, you will need to call setup_logging with arguments.
from hdx.utilities.easy_logging import setup_logging ... logger = logging.getLogger(__name__) setup_logging(KEYWORD ARGUMENTS)
KEYWORD ARGUMENTS can be:
Choose |
Argument |
Type |
Value |
Default |
---|---|---|---|---|
One of: |
logging_config_dict |
dict |
Logging configuration dictionary |
|
or |
logging_config_json |
str |
Path to JSON Logging configuration |
|
or |
logging_config_yaml |
str |
Path to YAML Logging configuration |
Library’s internal logging_configuration.yml |
One of: |
smtp_config_dict |
dict |
Email Logging configuration dictionary |
|
or |
smtp_config_json |
str |
Path to JSON Email Logging configuration |
|
or |
smtp_config_yaml |
str |
Path to YAML Email Logging configuration |
Do not supply smtp_config_dict, smtp_config_json or smtp_config_yaml unless you are using the default logging configuration!
If you are using the default logging configuration, you have the option to have a default SMTP handler that sends an email in the event of a CRITICAL error by supplying either smtp_config_dict, smtp_config_json or smtp_config_yaml. Here is a template of a YAML file that can be passed as the smtp_config_yaml parameter:
handlers: error_mail_handler: toaddrs: EMAIL_ADDRESSES subject: "RUN FAILED: MY_PROJECT_NAME"
Unless you override it, the mail server mailhost for the default SMTP handler is localhost and the from address fromaddr is noreply@localhost.
To use logging in your files, simply add the line below to the top of each Python file:
logger = logging.getLogger(__name__)
Then use the logger like this:
logger.debug('DEBUG message') logger.info('INFORMATION message') logger.warning('WARNING message') logger.error('ERROR message') logger.critical('CRITICAL error message')
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hdx-python-utilities-1.3.4.tar.gz
.
File metadata
- Download URL: hdx-python-utilities-1.3.4.tar.gz
- Upload date:
- Size: 35.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ddfe49cfd4d4a4df72537bb7411ce676ee16cda36e4d54443fb9eedcffb8d11 |
|
MD5 | ee1c4a735f8681ef6608d531d142951a |
|
BLAKE2b-256 | a3e4ca7b0e080c154ffd2c538ed9a2749e8e37b1ceba822488133f6cbe616f29 |
File details
Details for the file hdx_python_utilities-1.3.4-py2.py3-none-any.whl
.
File metadata
- Download URL: hdx_python_utilities-1.3.4-py2.py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3116b50d5c431f20baf971cc1450b4f5148726c0691da3b47a80901477d7a50 |
|
MD5 | d9d539607c6a61a9d305bbebe0366dcb |
|
BLAKE2b-256 | f8790345a12f9156e2733177b1cbbafe97f9e1f42dbf29adfb4b5a3109e4b5b0 |