# printstream
A Python library that enhances the built-in print function for better debugging.
## Table of Contents
1. [Features](#features)
2. [Installation](#installation)
3. [Usage](#usage)
4. [Configuration](#configuration)
5. [Examples](#examples)
6. [Overhead Measurement](#overhead-measurement)
7. [Contribution](#contribution)
8. [License](#license)
9. [Contact](#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:
```bash
pip install printstream
```
## Usage
Import and activate the library at the top of your script:
```python
from printstream import activate, deactivate
activate()
# Your code here...
deactivate()
```
## Configuration
Configure `printstream` to suit your needs:
```python
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`: If `repeat_func_name` is set to `False` and `align` is set to `True`, 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 to `True`, 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.
![image-20231103002159681](images/image-20231103002159681.png)
- `levels`: This option controls the output level.
- `-1`: No output
- `0`: Normal print
- `1`: Debug activated
## Examples
Example with `printstream` activated:
```python
from printstream import activate, deactivate
activate()
def test():
print("Hello World\nHow are you?")
test()
deactivate()
```
Output:
```plaintext
[test] Hello World
[test] How are you?
```
## Overhead Measurement
Measure the overhead of `printstream`:
```python
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](https://github.com/arnav-ag/printstream).
## License
`printstream` is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Contact
- Author: Arnav
- Email: arnavaggarwalwork@gmail.com
Raw data
{
"_id": null,
"home_page": "https://github.com/arnav-ag/printstream",
"name": "printstream",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Arnav",
"author_email": "arnavaggarwalwork@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4d/25/cc162adecdbfc19da2ed8a22f6e1f5eb2d24a373ecfd3a5e6230fa6d495c/printstream-0.1.3.tar.gz",
"platform": null,
"description": "# printstream\n\nA Python library that enhances the built-in print function for better debugging.\n\n## Table of Contents\n1. [Features](#features)\n2. [Installation](#installation)\n3. [Usage](#usage)\n4. [Configuration](#configuration)\n5. [Examples](#examples)\n6. [Overhead Measurement](#overhead-measurement)\n7. [Contribution](#contribution)\n8. [License](#license)\n9. [Contact](#contact)\n\n## Features\n- Prepend function name to print output.\n- Colorize function name based on hash for better visual distinction.\n- Align print output for improved readability.\n- Toggle enhanced print functionality on and off as needed.\n- Highly configurable via simple API.\n- Lightweight with minimal setup.\n\n## Installation\nInstall `printstream` via pip:\n```bash\npip install printstream\n```\n\n## Usage\nImport and activate the library at the top of your script:\n```python\nfrom printstream import activate, deactivate\n\nactivate()\n\n# Your code here...\n\ndeactivate()\n```\n\n## Configuration\nConfigure `printstream` to suit your needs:\n```python\nfrom printstream import (\n set_format, set_level, set_output, set_align, set_repeat_func_name,\n set_colorize, activate, deactivate\n)\n\n# Configure the debugger\nset_format(\"[{func_name}] {message}\")\nset_align(False)\nset_repeat_func_name(True)\nset_colorize(True)\nset_level(1)\n\nactivate()\n\n# Your code here...\n\ndeactivate()\n```\n\n### Additional Configuration Details\n\nHere are some additional details about the configuration options:\n\n- `align`: If `repeat_func_name` is set to `False` and `align` is set to `True`, the output of a single print statement with newlines will be indented such that the output is fully aligned.\n\n`align` and `repeat_func_name` set to `False`:\n```\n[test] Hello World\nHow are you?\n```\n\n- `repeat_func_name`: If a print statement has newlines, and this option is set to `True`, it will still print the function name before each line (even within the same print statement).\n\n```\n[test] Hello World\n[test] How are you?\n```\n\n- `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.\n\n![image-20231103002159681](images/image-20231103002159681.png)\n\n\n- `levels`: This option controls the output level.\n - `-1`: No output\n - `0`: Normal print\n - `1`: Debug activated\n\n\n## Examples\nExample with `printstream` activated:\n```python\nfrom printstream import activate, deactivate\n\nactivate()\n\ndef test():\n print(\"Hello World\\nHow are you?\")\n\ntest()\n\ndeactivate()\n```\n\nOutput:\n```plaintext\n[test] Hello World\n[test] How are you?\n```\n\n## Overhead Measurement\nMeasure the overhead of `printstream`:\n```python\nimport timeit\n\n# ... setup code ...\n\n# Measure time with standard print\ntime_without_debug = timeit.timeit(\"test()\", setup=setup_code, number=10)\n\n# Measure time with printstream activated\ntime_with_debug = timeit.timeit(\"activate(); test(); deactivate()\", setup=setup_code, number=10)\n\n# Calculate overhead percentage\noverhead_percentage = ((time_with_debug - time_without_debug) / time_without_debug) * 100\n```\n\n## Contribution\nContributions to `printstream` are welcome! Please submit a pull request or create an issue on the [GitHub repository](https://github.com/arnav-ag/printstream).\n\n## License\n`printstream` is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contact\n- Author: Arnav\n- Email: arnavaggarwalwork@gmail.com\n",
"bugtrack_url": null,
"license": "",
"summary": "A library for enhanced print debugging.",
"version": "0.1.3",
"project_urls": {
"Homepage": "https://github.com/arnav-ag/printstream"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f15f9bf20a37f19faa42275dd256a7440f1051dabf4d10e9ab7a227825ffa383",
"md5": "f9ee02b1a09d8dcc2718a8d074796d8b",
"sha256": "73299c646a6d74956b6c817b3502f0b83dd020e52541f25d70cb770a7b8fedba"
},
"downloads": -1,
"filename": "printstream-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f9ee02b1a09d8dcc2718a8d074796d8b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 4870,
"upload_time": "2023-11-02T16:48:26",
"upload_time_iso_8601": "2023-11-02T16:48:26.844647Z",
"url": "https://files.pythonhosted.org/packages/f1/5f/9bf20a37f19faa42275dd256a7440f1051dabf4d10e9ab7a227825ffa383/printstream-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4d25cc162adecdbfc19da2ed8a22f6e1f5eb2d24a373ecfd3a5e6230fa6d495c",
"md5": "c58a8a4e808f0c0cf96d2164304ef559",
"sha256": "99c4941c41b2d54de4a11e9286461b7d0bea881a9037a79418f49b7f41fcede1"
},
"downloads": -1,
"filename": "printstream-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "c58a8a4e808f0c0cf96d2164304ef559",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4273,
"upload_time": "2023-11-02T16:46:32",
"upload_time_iso_8601": "2023-11-02T16:46:32.318429Z",
"url": "https://files.pythonhosted.org/packages/4d/25/cc162adecdbfc19da2ed8a22f6e1f5eb2d24a373ecfd3a5e6230fa6d495c/printstream-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-02 16:46:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "arnav-ag",
"github_project": "printstream",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "printstream"
}