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.1.tar.gz (16.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.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: python_tap-0.1.1.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

Hashes for python_tap-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8647a69fd6b0c30b7a6d2f5a1891d64968cf1be6b8246514b23b1f8b21704b6f
MD5 8fc20a9f777406d1ef7ce54d5fe8b4c8
BLAKE2b-256 ee6d453ee8f4483d84282094a98b44900bd78970fd6b15c7c8ce5912c661d844

See more details on using hashes here.

File details

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

File metadata

  • Download URL: python_tap-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2e1778c09c7ce064c582ff7a0a41d55e4378342ced63fd0a00755eb941ae45c0
MD5 ebfb504bd64b8ff687171525594e6f0a
BLAKE2b-256 3d8a27d75dbcd41b99d9d43d454719b97676b9729898ea77388a214eb3d9b863

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