A small utility module built on top of rich for producing colourful, prettified drop-in replacement of built-in print() function.
Project description
Rich Console Utilities
A small utility module built on top of Rich for producing colourful, prettified drop-in replacement of built-in print() function.
The main contens are:
- A drop-in replacement for
print - A decorator for running functions with a spinner/status indicator like
npm
Installation
This module depends on Rich:
pip install themed-print
Usage
Pretty Print (Drop-in Replacement)
themed_print.print can be used as a drop-in replacement for the built-in print() function
from themed_print import print
print({
"name": "Alice",
"values": [1, 2, 3],
"active": True,
})
With custom indentation:
print(data, indent=2, show_guideline=True)
Arguments:
| Parameter | Type | Description |
|---|---|---|
content |
Any | Objects to print |
indent |
int | Spaces per indent level |
show_guideline |
bool | Show indentation guides |
sep |
str | Separator between values |
end |
str | Line ending |
Status Spinner Decorator
Run a function with a live spinner:
from themed_print import show_status
import time
@show_status("Running task…", exit_message="Done ✔")
def task():
for i in range(3):
time.sleep(0.5)
print("step", i)
task()
Supported parameters:
| Parameter | Description |
|---|---|
status_message |
Message shown while running |
exit_message |
Message printed after completion |
exit_message_style |
Rich style for exit message |
spinner |
Spinner name (see python -m rich.spinner) |
**status_kwargs |
Passed to Console.status() |
Instance Method Behaviour
If the decorated function is an instance method, logging is skipped when:
self._show_status = False
This allows silent execution in batch or test modes.
Customisation
The colour schemed is implemented through rich.theme.Theme object with customised regex highlighter themed_print.DTypeRegexHighlighter.
Currently, colour schemes are defined in themed_print.config.DEFAULT_THEME Support for custom theming is planned for future releases.
Author
Yiheng Yu Created: Jan 1, 2025
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 Distributions
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 themed_print-0.1.3-py3-none-any.whl.
File metadata
- Download URL: themed_print-0.1.3-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1857cef1949090f69b12e33c6b923527b26290dfe35bad7ede8c28ddbed4de65
|
|
| MD5 |
1f588d140c80c687b8baee75ead82b33
|
|
| BLAKE2b-256 |
025ea9f2a1df22d484053c388629ea14a839e18d9b8158eec4709ef10a63f9cd
|