Skip to main content

constable allows you to monitor the state of specified variables at each assignment operation, providing a step-by-step view of variable changes!

View the Github repository and the official docs.

How does it work?

The constable.trace decorator uses Python’s Abstract Syntax Tree (AST) in much the same way we add print`(s) to debug states. During runtime, it prepares and inserts `print statements into the function’s AST after every assignment operation (ast.Assign, ast.AugAssign and ast.AnnAssign), and then executes the modified code in a separate namespace with exec.

$ pip install constable

Tested for python 3.8 and above.

Usage :

Tracking variables in a function

import constable

@constable.trace('a', 'b')
def example(a, b):
    a = a + b
    c = a
    a = "Experimenting with the AST"
    b = c + b
    a = c + b
    return a

example(5, 6)

Output :

constable: example: line 5
    a = a + b
    a = 11
    type(a) = <class 'int'>

constable: example: line 7
    a = "Experimenting with the AST"
    a = Experimenting with the AST
    type(a) = <class 'str'>

constable: example: line 8
    b = c + b
    b = 17
    type(b) = <class 'int'>

constable: example: line 9
    a = c + b
    a = 28
    type(a) = <class 'int'>

constable: example: line 3 to 10
    args: (5, 6)
    kwargs: {}
    returned: 28
    execution time: 0.00018480 seconds

Monitor functions

import constable

@constable.trace()
def add(a, b):
    return a + b

add(5, 6)

Output :

constable: add: line 3 to 5
    args: (5, 6)
    kwargs: {}
    returned: 11
    execution time: 0.00004312 seconds

Metadata

Release files for constable 0.3.1

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

Source distribution (sdist)

Source distribution for constable 0.3.1
File Size Uploaded Provenance Actions
constable-0.3.1.tar.gz 5.3 kB Without provenance Details for constable-0.3.1.tar.gz

Built distribution (wheel)

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

Total release size: 10.7 kB

Release files / constable-0.3.1.tar.gz

Download URL constable-0.3.1.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
26e637b00145212916e1df0cdbb5d9a300959fdfa808c10c1fb98b712e4088a5
BLAKE2b-256 checksum
How to use checksums
f70a4da4d32b287caa1891768925ec4aedfe6e2dc56da6826e7f1bc424074376
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.13

Release files / constable-0.3.1-py3-none-any.whl

Download URL constable-0.3.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
179dc03535ec03af770f9e660d639ad32c6e7f2bf6cd1738e332cdf2c6d1f531
BLAKE2b-256 checksum
How to use checksums
e625b7e5e68fec9fe68d6ea2b80dedded3a2e53a8f1dd1fb8fbb6faa22d6609a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.13

Security for constable 0.3.1

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.

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