Skip to main content

Python Tap

A tool for REPL Driven Development.

What is Python Tap?

Python Tap is used during development and when running code. With this tool, you can store and process data such as function input parameters or local variables. This is very useful when inspecting code and flows, and when running code in a REPL. You will have all the tapped data available in the session.

It is closely related to the variables available when debugging, but you have the data available from anywhere in the code base.

You can use Python Tap when running code in debug mode too.

Python Tap itself, doesn't do any processing of data, but the functions you add to the tap does that. Included in this library, there are default taps. You can also write your own, or add any existing function accepting *args and **kwargs (such as a logger).

You decorate functions, or call the tap function directly. The tap function will run the added taps (functions) with the input to the target function.

This library heavily inspired by the tap> feature in Clojure.

Usage

from python_tap import tap


@tap
def my_function(message: str, data: dict):
    ...
    
    
my_function("hello world", {"key": "value"})

Python Tap will not do anything until adding a function to the tap storage. Let's do that.

import python_tap


# this is an example tap function
def print_data(*args, **kwargs):
    print(f"{args} {kwargs}")


# Add your function(s) to the tap storage
python_tap.add(print_data)
my_function("hello world", {"key": "value"})

The output:

('hello world', {'key': 'value'}) {'tap_fn': <function my_function at 0x103d4d940>}

Adding the included data storage tap, to be able to work with the input data at anytime in the REPL session.

from python_tap import taps


python_tap.add(taps.params.store)

Run the my_function again. This tap doesn't print anything, but it has stored all data.

# get the stored data from the function
tapped = taps.params.get(my_function)

# or get all stored data from all decorated functions
tapped = taps.params.get_all()


print(tapped["message"]) # will print the string "hello world"
print(tapped["data"]) # will print the dictionary {'key': 'value'}

Removing taps:

# Remove a single tap, i.e. the tap function
python_tap.remove(print_data)

# Or, remove all taps
python_tap.remove()

Metadata

Release files for python-tap 0.1.3

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

Source distribution (sdist)

Source distribution for python-tap 0.1.3
File Size Uploaded
python_tap-0.1.3.tar.gz 16.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-tap 0.1.3
File Interpreter ABI Platform
python_tap-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 21.9 kB

Release files / python_tap-0.1.3.tar.gz

Download URL python_tap-0.1.3.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d00c42c3df8c8eed4958e94df5c8cac8c10ca4910b9763c9f70a6e2e78fff59e
BLAKE2b-256 checksum
How to use checksums
f64a5747eeb8a5c7dde3878395c7f29f6a0058662ab91af1df2f3ca53b047066
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release files / python_tap-0.1.3-py3-none-any.whl

Download URL python_tap-0.1.3-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2592c82a54eacd5f9e8aa206e25129babb2b8365b19346c75b814157a0c5f318
BLAKE2b-256 checksum
How to use checksums
eb466dcfe38cb63ad4254db0d4559a8e21cf962a6f1601c38b1cbf3a91eb3d2b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.0

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

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