Skip to main content

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.store.get(my_function)

# or get all stored data from all decorated functions
tapped = taps.params.store.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

python_tap-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

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

python_tap-0.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file python_tap-0.1.0.tar.gz.

File metadata

  • Download URL: python_tap-0.1.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for python_tap-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9b2bddd1dc9aca8fb1fedd5649825ae9b415b84c79b3d84e20b8f84595499beb
MD5 be16f65ac36283b49559264d09d09852
BLAKE2b-256 c2b16a6e08a5ca53d3a68232e6293996a478ec367b09634efe452b1c9b9e615d

See more details on using hashes here.

File details

Details for the file python_tap-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_tap-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.0

File hashes

Hashes for python_tap-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f465d2e4ea8ae836296180700571bc9b6b124dd44d48d1529e649fc8ac17f04
MD5 be2c845edc0acbb76eb747ab971cbfe8
BLAKE2b-256 46dd4d86f0988cd792e7c65dc742f2d644db5043558d52649ab015204250be00

See more details on using hashes here.

Supported by

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