Skip to main content

magichash

magichash is a tiny debugging decorator that injects print statements at runtime based on ### markers in your function body — no manual print calls needed.

Install

pip install magichash

For local development:

pip install -e .

Quick Start

from magichash import register

@register
def foo(x, y):
    z = x + y  ###
    w = z * 2  ### z,w
    return w

foo(2, 3)
# foo.py:3: z: 5
# foo.py:4: 
#     z: 5, 
#     w: 10, 

Marker rules

Marker Behaviour
z = x + y ### Auto-print assignment targets (z)
z = x + y ### z,w Print the listed expressions (z, w)
x, y ### On non-assignment lines, print the comma-separated names before ###

Custom mark and callback

Use register(mark=..., callback=...) to override the marker string or the print handler:

from magichash import register

def my_print(loc, var_dict):
    print(f"[DEBUG] {loc}: {var_dict}")

@register(mark="#//", callback=my_print)
def bar(x, y):
    z = x * y  #// x,y
    z = x + y  #//
    return z

bar(2, 3)
# [DEBUG] bar.py:3: {'x': 2, 'y': 3}
# [DEBUG] bar.py:4: {'z': 5}

API

register(func=None, *, mark="###", callback=do_print)

Decorator that instruments a function. Can be used in two ways:

@register                          # default mark=### and built-in printer
@register(mark="#==", callback=fn) # custom mark / callback

do_print(loc, var_dict)

The default callback. Prints coloured file:line: name: value output to stdout.

Build and Publish

python -m build
python -m twine upload dist/*

Metadata

Release files for magichash 0.1.0

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

Source distribution (sdist)

Source distribution for magichash 0.1.0
File Size Uploaded Provenance Actions
magichash-0.1.0.tar.gz 4.2 kB Without provenance Details for magichash-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for magichash 0.1.0
File Interpreter ABI Platform Actions
magichash-0.1.0-py3-none-any.whl Python 3 none any Details for magichash-0.1.0-py3-none-any.whl

Total release size: 9.0 kB

Release files / magichash-0.1.0.tar.gz

Download URL magichash-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0281678634e36df6691c1b4006aa9b8a15c1502e787a092ccaf3a4ae1fdf1b31
BLAKE2b-256 checksum
How to use checksums
7a918bdfc0ee1364b0a88382be4390ef48a357bcf7831a9139708d7be59adfe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / magichash-0.1.0-py3-none-any.whl

Download URL magichash-0.1.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81113cf0002355cc07167a01b0929da30857994a3c7271ffcad17c5c227ff092
BLAKE2b-256 checksum
How to use checksums
939c3f9a04210f803fbd73f50b71f8f9db35e296c9854b40cbf907de821ef338
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Security for magichash 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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