A library for enhanced print debugging.
Project description
printstream
A Python library that enhances the built-in print function for better debugging.
Table of Contents
- Features
- Installation
- Usage
- Configuration
- Examples
- Overhead Measurement
- Contribution
- License
- Contact
Features
- Prepend function name to print output.
- Colorize function name based on hash for better visual distinction.
- Align print output for improved readability.
- Toggle enhanced print functionality on and off as needed.
- Highly configurable via simple API.
- Lightweight with minimal setup.
Installation
Install printstream
via pip:
pip install printstream
Usage
Import and activate the library at the top of your script:
from printstream import activate, deactivate
activate()
# Your code here...
deactivate()
Configuration
Configure printstream
to suit your needs:
from printstream import (
set_format, set_level, set_output, set_align, set_repeat_func_name,
set_colorize, activate, deactivate
)
# Configure the debugger
set_format("[{func_name}] {message}")
set_align(False)
set_repeat_func_name(True)
set_colorize(True)
set_level(1)
activate()
# Your code here...
deactivate()
Additional Configuration Details
Here are some additional details about the configuration options:
align
: Ifrepeat_func_name
is set toFalse
andalign
is set toTrue
, the output of a single print statement with newlines will be indented such that the output is fully aligned.
align
and repeat_func_name
set to False
:
[test] Hello World
How are you?
repeat_func_name
: If a print statement has newlines, and this option is set toTrue
, it will still print the function name before each line (even within the same print statement).
[test] Hello World
[test] How are you?
colorize
: This option colorizes the function name based on its hash. This introduces some significant overhead (~200%). If anyone has any suggestions on improvements, please submit a PR.
levels
: This option controls the output level.-1
: No output0
: Normal print1
: Debug activated
Examples
Example with printstream
activated:
from printstream import activate, deactivate
activate()
def test():
print("Hello World\nHow are you?")
test()
deactivate()
Output:
[test] Hello World
[test] How are you?
Overhead Measurement
Measure the overhead of printstream
:
import timeit
# ... setup code ...
# Measure time with standard print
time_without_debug = timeit.timeit("test()", setup=setup_code, number=10)
# Measure time with printstream activated
time_with_debug = timeit.timeit("activate(); test(); deactivate()", setup=setup_code, number=10)
# Calculate overhead percentage
overhead_percentage = ((time_with_debug - time_without_debug) / time_without_debug) * 100
Contribution
Contributions to printstream
are welcome! Please submit a pull request or create an issue on the GitHub repository.
License
printstream
is licensed under the MIT License. See the LICENSE file for details.
Contact
- Author: Arnav
- Email: arnavaggarwalwork@gmail.com
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file printstream-0.1.3.tar.gz
.
File metadata
- Download URL: printstream-0.1.3.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.31.0 requests-toolbelt/1.0.0 urllib3/1.26.16 tqdm/4.65.0 importlib-metadata/6.8.0 keyring/23.13.1 rfc3986/1.5.0 colorama/0.4.6 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99c4941c41b2d54de4a11e9286461b7d0bea881a9037a79418f49b7f41fcede1 |
|
MD5 | c58a8a4e808f0c0cf96d2164304ef559 |
|
BLAKE2b-256 | 4d25cc162adecdbfc19da2ed8a22f6e1f5eb2d24a373ecfd3a5e6230fa6d495c |
File details
Details for the file printstream-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: printstream-0.1.3-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73299c646a6d74956b6c817b3502f0b83dd020e52541f25d70cb770a7b8fedba |
|
MD5 | f9ee02b1a09d8dcc2718a8d074796d8b |
|
BLAKE2b-256 | f15f9bf20a37f19faa42275dd256a7440f1051dabf4d10e9ab7a227825ffa383 |