A Python implementation of tap. Useful for REPL Driven Development.
Project description
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()
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_tap-0.1.3.tar.gz.
File metadata
- Download URL: python_tap-0.1.3.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d00c42c3df8c8eed4958e94df5c8cac8c10ca4910b9763c9f70a6e2e78fff59e
|
|
| MD5 |
40ce5cbc4bca83b02bc392caa4d98fae
|
|
| BLAKE2b-256 |
f64a5747eeb8a5c7dde3878395c7f29f6a0058662ab91af1df2f3ca53b047066
|
File details
Details for the file python_tap-0.1.3-py3-none-any.whl.
File metadata
- Download URL: python_tap-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2592c82a54eacd5f9e8aa206e25129babb2b8365b19346c75b814157a0c5f318
|
|
| MD5 |
2c92921d4409d1642e387803b849f953
|
|
| BLAKE2b-256 |
eb466dcfe38cb63ad4254db0d4559a8e21cf962a6f1601c38b1cbf3a91eb3d2b
|