Skip to main content

Humbug Python

The Humbug Python library.

Installation

Using pip

pip install humbug

From source

Clone this repository and enter this directory. Make sure you are in your desired Python environment and then run:

python setup.py install

Integration

To add Humbug to your project, first create a Bugout access token and journal following these instructions.

You can follow the recipes below to integrate Humbug into your codebase:

  1. Error reporting
  2. System reporting

All reports are generated (and published) by a Humbug reporter. By default, Humbug publishes all reports asynchronously and in the background. If you would like to publish selected reports synchronously, all reporter methods take a wait=True argument.

If you plan to only use a reporter synchronously or to do your own thread management, you can instantiate the reporter in synchronous mode:

from humbug.report import Reporter, Modes

reporter = Reporter(
    "<name>",
    client_id="<client_id>",
    session_id="<session_id>",
    bugout_token="<bugout_token>",
    bugout_journal_id="<bugout_journal_id>",
    mode=Modes.SYNCHRONOUS,
)

Using Modes.SYNCHRONOUS in this manner skips the creation of the thread from which the reporter publishes reports.

Consent

Humbug cares deeply about consent. The innocuous HumbugConsent from the snippet above supports a wide range of consent flows.

Opting in with environment variables

For example, if you would like your users to be able to opt in by setting an environment variable MY_APP_CONSENT=true:

from humbug.consent import environment_variable_opt_in, HumbugConsent
from humbug.report import Reporter

consent = HumbugConsent(environment_variable_opt_in("MY_APP_CONSENT", ["true"]))
reporter = Reporter(
    "<name of your project>",
    consent,
    bugout_token="<your Bugout token>",
    bugout_journal_id="<your Bugout journal ID>",
)

If you use this configuration, unless your user uses your tool with MY_APP_CONSENT=true, no reports will ever get sent to your knowledge base.

Opting out with environment variables

If, like homebrew, you would like users to be able to opt out by setting an environment variable MY_APP_NO_CONSENT=1:

from humbug.consent import environment_variable_opt_out, HumbugConsent
from humbug.report import Reporter

consent = HumbugConsent(environment_variable_opt_out("MY_APP_NO_CONSENT", ["1"]))
reporter = Reporter(
    "<name of your project>",
    consent,
    bugout_token="<your Bugout access token>",
    bugout_journal_id="<your Bugout journal ID>",
)

In this case, reports are sent by default unless the user sets MY_APP_NO_CONSENT=1 in which case reports will never be sent.

Composing consent mechanisms

Humbug allows you to combine multiple consent mechanisms. For example:

from humbug.consent import environment_variable_opt_in, environment_variable_opt_out, HumbugConsent
from humbug.report import Reporter

consent = HumbugConsent(
    environment_variable_opt_in("MY_APP_CONSENT", ["true"]),
    environment_variable_opt_out("MY_APP_NO_CONSENT", ["1"]),
)
reporter = Reporter(
    "<name of your project>",
    consent,
    bugout_token="<your Bugout access token>",
    bugout_journal_id="<your Bugout journal ID>",
)

If your users do not set MY_APP_CONSENT or give it a value other than true, Humbug won't even bother to send you any reports. If MY_APP_CONSENT is indeed set to true, but the user has set MY_APP_NO_CONSENT=1, then again no reports will get sent back.

On the other hand, if the user has set MY_APP_CONSENT=true and left MY_APP_NO_CONSENT unset or set to a value other than 1, Humbug will send you any reports you have configured.

Blacklisting parameters in feature reports

Arguments to functions and other callables can sometimes contain sensitive information which you may not want to include in Humbug reports.

Blacklist functions allow you to specify which parameters from an argument list to filter out of your feature reports.

blacklist.generate_filter_parameters_by_key_fn

If you would just like to filter out all paramters with a given name, you can use the blacklist.generate_filter_parameters_by_key_fn.

For example, to ignore all parameters named token (case insensitive), you would instantiate your HumbugReporter as follows:

reporter = HumbugReporter(
    ...,
    blacklist_fn=blacklist.generate_filter_parameters_by_key_fn(["token"]),
)

Custom blacklist functions

You could also implement a custom blacklist function to remove all parameters that contained the substring token (case insensitive):

def blacklist_token_parameters_fn(params: Dict[str, Any]) -> Dict[str, Any]:
    admissible_params = {k:v for k, v in params.items() if "token" not in k}
    return admissible_params

reporter = HumbugReporter(
    ...,
    blacklist_fn=blacklist_token_parameters_fn
)

Case study: activeloopai/deeplake

This pull request shows how Activeloop integrated Humbug into their popular deeplake tool.

This example shows how to use Humbug to record consent in a configuration file that the user can modify at will. It also shows how to add custom tags to your Humbug reports.

Metadata

Release files for humbug 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for humbug 0.3.2
File Size Uploaded
humbug-0.3.2.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for humbug 0.3.2
File Interpreter ABI Platform
humbug-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 29.9 kB

Release files / humbug-0.3.2.tar.gz

Download URL humbug-0.3.2.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
0fca3cdb6db2348e13d7835b1a743ff545e38344fc55ad4e2a083634b12a0a6e
BLAKE2b-256 checksum
How to use checksums
f8dbb273e70c2151f5b8d1c915a43e94fcd056fcdb0d2a1c52d24d468cd72d5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / humbug-0.3.2-py3-none-any.whl

Download URL humbug-0.3.2-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d302c82019842f4267ed05b54a26b155ab8dc441ac129e2a62c9c4892d53c71
BLAKE2b-256 checksum
How to use checksums
c8ccc8129d6e9a1f473b5e90cf1b8eac43191a22657b9b673e02815548662270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.2.4

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.14

2 release files

0.1.13

2 release files

0.1.12

2 release files

0.1.11

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page