Skip to main content
Behold
===
Working with real-world code inevitably involves a lot of debugging time. In
order to get a full understanding of what your code is doing, you will need to
monitor its internal state as it is executed. There are two main ways to do
this: step-debuggers, and print statements. Behold is a tool that can be used
for either one of these work flows, but is focused mainly on logging program
state to the console as it is being run. Think of it as a tool to help you
remove a lot of boiler-plate code when you want to drop into your code and
examine state.

Contextual Debugging
---
Behold enables you to do contextual debugging. What this means is that you will
be able to control when you dump state in a module depending on the context of
how it is being used in another module. For large code bases such as Django
projects, where your state can be spread across multiple apps and even the
database, such context-aware debugging becomes quite valuable.

Perhaps this is best explained with an example. Let's say you have the
following module. You've defined it in its own module because it is used all
over your code base and you've factored it out to maximize your code reuse.
You have added a Behold state logger that will show the `value` attribute of the
metric, but only if processing in the `action='handler'` context.
```python
#####################################################################
# processor.py
#####################################################################

from behold import Behold
from my_complicated_module import do_something_hard

def process(metric):
# Adding this line to your cold will log the metric value to the console
# but only if in the proper context
#
# Note that we could also filter on metric properties and show multiple
# metric attributes like this.
# Behold().when(metric.entity='Boston').show(t=metric.time, v=metric.value)
#
Behold().when_in_context(action='handler').show(value=metric.value)

do_something_hard(metric)
```

In a completely different package of your code base you call your processor
on two different sets of metrics, and you want to be able to log those metrics
in the processor, but only when being processed in the `handler` context.

```python
#####################################################################
# master.py
#####################################################################
from processor import process
from behold import in_context

# Here we decorate a handler with a named context
@in_context(action='handler')
def handle_vendors():
metrics = get_vendor_metrics()
process(metrics)

def handle_customers():
metrics = get_customer_metrics()

# here we set the context using a with statement
with in_context(action='handler'):
process(metrics)
```

When you program is run, you would then see output like the following printed to
your console

```bash
value: 0.1
value: 0.2
value: 0.3
```

Download files

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

Source Distribution

behold-0.0.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

behold-0.0.2-py2.py3-none-any.whl (9.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file behold-0.0.2.tar.gz.

File metadata

  • Download URL: behold-0.0.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for behold-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fc9149b2ce5aea10dedfe84c98d27c1f78adbdb00ee52ca7433df17c24b59d8c
MD5 e504d222d6fcc6f33f40645537b2a657
BLAKE2b-256 a9eb05dd9b8a4a0db8b983031f950bb901f9f4ea7cad381b587e6fc9a36e602c

See more details on using hashes here.

File details

Details for the file behold-0.0.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for behold-0.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 874b1e4b9d9eb63f4dbfae14b033a3b3582fc16ec6043a072db90e940b70febf
MD5 9dbb575f142835e8e012794dbcb466a3
BLAKE2b-256 0f521426fa9b591cf135017fab3d9778a55115da266058feaab52e3918ccfced

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

This release

0.0.2 This release

2 files

0.0.1

2 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