Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

themed_print-0.1.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file themed_print-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: themed_print-0.1.2-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

Hashes for themed_print-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b4c67dd4308f334d55346813d960434ee78fdc27e14c169e7d19e4ff80f351b1
MD5 e50e3bb389d6268bba3c4a6fdfdf8486
BLAKE2b-256 0a7c073a06cf4d86de21149c8fccb51b0852b03f80c8888bbe48e75fe58a6628

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page