Skip to main content

HDX Python Utilities

Project description

Travis-CI Build Status Coveralls Build Status

The HDX Python Utilities Library provides a range of helpful utilities:

  1. Easy downloading of files with support for authentication, streaming and hashing

  2. Simple emailing

  3. Easy logging setup

  4. Dictionary and list utilities

  5. Text block matching

  6. Path utilities

  7. 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

This version

1.3.3

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hdx-python-utilities-1.3.3.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hdx_python_utilities-1.3.3-py2.py3-none-any.whl (23.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file hdx-python-utilities-1.3.3.tar.gz.

File metadata

File hashes

Hashes for hdx-python-utilities-1.3.3.tar.gz
Algorithm Hash digest
SHA256 a7cc6bbc6dda81bc6072dedd6516816b7c22913b26b19f0c781d3193ac436bc1
MD5 baf4782c75820c0ebc75d7cc0b61dc1f
BLAKE2b-256 a3295d4c28f0d698272681067d81d6648018c400cf193cbe2da2e553230db637

See more details on using hashes here.

File details

Details for the file hdx_python_utilities-1.3.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for hdx_python_utilities-1.3.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 9cce00b06c1b235af48fbcf263f284e2e513c58f2b7715dcd3774b1a0e2e2542
MD5 fcc669de68fcc74cceec8114993a47d8
BLAKE2b-256 50af6229e2b8483a4da2028431e0c9177b4a965d205f73e75b8b2b67c5f57c0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page