Package for colored organized verbose printing in python.
Project description
Pretty Verbose
Package for beautiful verbose printing in python.
Installation
The package is available in the Python Package Index (PyPi).
python3 -m pip install pretty_verbose
Examples
Simple output
To use the verbose output, create a VerboseMessages object.
from pretty_verbose import VerboseMessages
messages = VerboseMessages(
level=3,
name="main",
filename="messages.log",
log_dir="path/to/log_dir" # Optional for saving the log in the given dir.
)
The level indicates which messages will be printed.
- -1: Just Debug.
- 0: Debug and Errors.
- 1: Debug, Errors and Warnings.
- 2: Debug, Errors Warnings and Success.
- 3: Debug, Errors Warnings, Success and Info.
The name works to use the VerboseMessages in several instance and differentiate where the message is coming from. Finally the filename will store all the messages printed in the terminal.
The following messages can be printed.
import time
messages.debug("This is a debug message.")
messages.error("This is an error message.")
messages.warning("This is a warning message.")
messages.success("This is a success message.")
messages.info("This is an info message.")
for i in range(100):
if i % 10 == 0:
messages.for_message("This is an info message inside a for loop.")
messages.progress("This is a progress message.", (i+1))
time.sleep(0.1)
The result will be the following.
[28/08/2022 14:12:09] DEBUG [main]: This is an debug message.
[28/08/2022 14:12:09] ERROR [main]: This is an error message.
[28/08/2022 14:12:09] WARNING [main]: This is a warning message.
[28/08/2022 14:12:09] SUCCESS [main]: This is a success message.
[28/08/2022 14:14:06] SUCCESS [main]: This is a success message.
[28/08/2022 14:12:10] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:11] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:13] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:14] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:15] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:16] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:17] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:18] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:19] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:12:20] INFO [main] -- This is an info message inside a for loop.
[28/08/2022 14:14:19] INFO [main] -- This is a progress message.: [100.00%]
Tasks and Processes
There are more complete classes such as Task and Process that allow
measurement of execution time as well as creating subordinate verbose messages.
Both are equipped with all the printing function as they are inherited from the
VerboseMessages class.
With Task it is possible to measure how long it takes to complete a execution of a function:
task1 = Task(level=5, name="task1")
ex_time = task1.exec_time(
some_callable, # Function from which measure the execution time.
arg1, arg2, # Arguments of the function.
print_timer=True # Print the time execution as it just return it.
)
ex_time = task1.exec_many_time(
callable1, callable2, callable3, # Functions from which measure the execution time.
[[f1_arg1, f1_arg2], [], [f3_arg1]], # Arguments of the functions.
print_timer=True # Print the time execution as it just return it.
)
Additionally it is possible just to activate, deactivate, get the partial and total time of the timer.
task1.start_timer()
# ...some code ...
lap_time = task1.lap()
# ...some code ...
task1.print_lap()
# ...some code ...
task1.stop_timer()
total_t = task1.total_time()
With Process it is possible to create subtasks and subprocesses associated to
it.
main_process = Process(level=5, name="main")
subprocess_1: Process = main_process.new_subprocess("subprocess_1")
subprocess_2: Process = main_process.new_subprocess("subprocess_2")
subtask_2: Task = main_process.new_task("subtask_1")
# Subprocess as they are Process object, they can also create new processes and
# tasks.
subsubprocess_1: Process = subprocess_1.new_subprocess("subsubprocess_1")
subsubtask_2: Task = subprocess_1.new_task("subsubtask_1")
All the Process objects are also equipped with the timer functions as it
inherits from the Task class.
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
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 pretty_verbose-0.1.2.post3.tar.gz.
File metadata
- Download URL: pretty_verbose-0.1.2.post3.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
729553da2c56b9edf7c6e9f147f1a7c21f272b2629983fe833f50a4b7dfc75ba
|
|
| MD5 |
2029fd0e060faf24209272b26bca2e48
|
|
| BLAKE2b-256 |
ac7bb23bc6ae2f7a86ce76920e10b8d616fc45013e4bcb12941e31ab3424c120
|
Provenance
The following attestation bundles were made for pretty_verbose-0.1.2.post3.tar.gz:
Publisher:
python-publish.yml on ccmorenos/pretty_verbose
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pretty_verbose-0.1.2.post3.tar.gz -
Subject digest:
729553da2c56b9edf7c6e9f147f1a7c21f272b2629983fe833f50a4b7dfc75ba - Sigstore transparency entry: 197197559
- Sigstore integration time:
-
Permalink:
ccmorenos/pretty_verbose@3b244237b83ea64a37446279d8c96dee7fc0a0e7 -
Branch / Tag:
refs/tags/v0.1.2-3 - Owner: https://github.com/ccmorenos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@3b244237b83ea64a37446279d8c96dee7fc0a0e7 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pretty_verbose-0.1.2.post3-py3-none-any.whl.
File metadata
- Download URL: pretty_verbose-0.1.2.post3-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a7681454c5cbb094a6844b28ca1b20b82381f18394a82423b5b5d0994f17b34
|
|
| MD5 |
fd06f91c10c6049fd929ae95e53f13f6
|
|
| BLAKE2b-256 |
53d8a4e56b639caa6ef09e0bb02b97770b5d2da28f8a0d0a1e9bad06febb5399
|
Provenance
The following attestation bundles were made for pretty_verbose-0.1.2.post3-py3-none-any.whl:
Publisher:
python-publish.yml on ccmorenos/pretty_verbose
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pretty_verbose-0.1.2.post3-py3-none-any.whl -
Subject digest:
3a7681454c5cbb094a6844b28ca1b20b82381f18394a82423b5b5d0994f17b34 - Sigstore transparency entry: 197197562
- Sigstore integration time:
-
Permalink:
ccmorenos/pretty_verbose@3b244237b83ea64a37446279d8c96dee7fc0a0e7 -
Branch / Tag:
refs/tags/v0.1.2-3 - Owner: https://github.com/ccmorenos
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@3b244237b83ea64a37446279d8c96dee7fc0a0e7 -
Trigger Event:
release
-
Statement type: