print-less debugging
Project description
pled – print-less debugging
pled is a library for debugging Python code so you don't have to paste print() everywhere.
It features no-code instrumentation on your codebase.
Getting started
-
Install
pledas a library# With poetry poetry add --dev pled # With uv uv add --dev pled
-
Use an executor to execute code and collect traces into a tracer
# Tracing function `bar(*args, **kwargs)` inside module `foo` from pled import Executor executor = Executor("foo") tracer = executor.execute_function("bar", *args, **kwargs)
-
Inspect the traces in a tracer
# Print the traces print(tracer.format_traces()) # Or dump into stringified JSON json_traces = tracer.dump_json()
Types of traces
pled traces the following types of events:
FunctionEntry- function entryfunction_name- fully qualified function nameargs- the full argument list in name-value pairstimestamp- timestamp of the event
FunctionExit- function exitfunction_name- fully qualified function namereturn_value- return valuetimestamp- timestamp of the event
Branch- branchingfunction_name- fully qualified function name where the branch is locatedbranch_type- branch type, can beif,while, orexceptcondition_expr- condition expressionevaluated_values- evaluated valuescondition_result- condition resulttimestamp- timestamp of the event
Await- await expressionfunction_name- fully qualified function name where the await is locatedawait_expr- await expressionawait_value- value being awaitedawait_result- result of the awaittimestamp- timestamp of the event
Yield- yield expressionfunction_name- fully qualified function name where the yield is locatedyield_value- value being yieldedtimestamp- timestamp of the event
YieldResume- yield resumptionfunction_name- fully qualified function name where the yield is locatedsend_value- value being sent to the generatortimestamp- timestamp of the event
Note: timestamp is a float representing the number of seconds since the start of the
execution.
Examples
Tracing a module
Given this module:
# Module: your_project.main
def just_print():
print("hello")
just_print() # <-- this module does some work directly
You can trace the execution of this module by running:
from pled import Executor
executor = Executor("your_project.main")
tracer = executor.execute_module()
print(tracer.format_traces())
Tracing a function
Given this module without root-level execution:
# Module: your_project.add
def just_add(a: int, b: int) -> int:
return a + b
You can trace the execution of a function by running:
from pled import Executor
executor = Executor("your_project.add")
tracer = executor.execute_function("just_add", 1, 2)
print(tracer.format_traces())
Tracing multiple modules
You can trace multiple modules by passing a list of package or module names to the
Executor constructor.
Suppose you want to trace everything inside your_project package when executing
your_project.add.just_add function.
from pled import Executor
executor = Executor("your_project.add", includes=["your_project"])
tracer = executor.execute_function("just_add", 1, 2)
print(tracer.format_traces())
Tracing a function with background execution
You can run the executor in the background by setting the background option to True.
Given this module:
# Module: your_project.event_loop
def infinite_yield():
import time
while True:
time.sleep(0.5)
yield 1
def loop():
for _ in infinite_yield():
pass
You can run loop() in the background with:
from pled import Executor
executor = Executor("your_project.event_loop", background=True)
tracer = executor.execute_function("loop")
while True:
time.sleep(1)
print(tracer.format_traces())
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 pled-0.1.0.tar.gz.
File metadata
- Download URL: pled-0.1.0.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d02b572b88bb57c8cc5a4485301ccec64c8d95d29dbc9488ac89f93630295c1f
|
|
| MD5 |
9ebd1949dc670216f058d9299e9a7464
|
|
| BLAKE2b-256 |
938690e7312ae1769efd5261ab5d0ed0a10c0a960e2a6fdaa2b36767d28831f8
|
File details
Details for the file pled-0.1.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: pled-0.1.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 291.3 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7885dc2c615a8abf5d7325980e6575fc913fea81175540af076b7e42929f9bb6
|
|
| MD5 |
12a3ff0a502b3851e64fdf37493fa8b3
|
|
| BLAKE2b-256 |
4b3321ef7b3648b9d0c5776ae8a15e26a3bb7d567e1057f33f70b72f4f6f3107
|