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

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.4.8.tar.gz (37.1 kB view details)

Uploaded Source

Built Distribution

hdx_python_utilities-1.4.8-py2.py3-none-any.whl (22.1 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: hdx-python-utilities-1.4.8.tar.gz
  • Upload date:
  • Size: 37.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for hdx-python-utilities-1.4.8.tar.gz
Algorithm Hash digest
SHA256 8d6b07e4305a0d3c9dfa7341d4954b3220c7b4832dae482f360e4cac065625b2
MD5 0048f38fb4acde07a512cc797caf708f
BLAKE2b-256 15be7d67af41d8b937189be661c4074b41b54f1ea475a0fadc7d84871a64d6b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hdx_python_utilities-1.4.8-py2.py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.5

File hashes

Hashes for hdx_python_utilities-1.4.8-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 bee32a36f0ad7f4e0b39747e2fef6274d081911310fb7840b1565b4a30caa9d3
MD5 26ea9aeb78b103292de81aa6499c2ebb
BLAKE2b-256 684c620ba54cf08273cceaac3a4fdce15cad880c9ac47ac5acd3a550678065e0

See more details on using hashes here.

Supported by

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