Registry / observability / enrich

enrich

JSON →
library1.2.7pypypi✓ verified 27d ago

The `enrich` library extends the functionality of the popular `rich` library, providing additional features not natively included in `rich`. It offers a custom `Console` class with support for redirecting `sys.stdout`/`sys.stderr` and implicit soft wrapping, as well as an alternative `RichHandler` for logging that prioritizes soft wrapping. The current stable version is 1.2.7, with releases occurring periodically to maintain compatibility with `rich` and add minor enhancements.

pip install enrich
INSTALL
IMPORT
SIG · ENRICH
E
enrich
observabilitypythonv1.2.7
Install
2.6s avg
Import
103ms
Disk
29MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.2.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.106s · 30.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.6s · import 0.100s · 31MB
29MB installed
● package 29MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Console
✓ from enrich.console import Console
✗ from rich.console import Console
The `enrich` Console class includes additional features like `redirect` and `soft_wrap` parameters not present in the original `rich.console.Console`.
RichHandler
✓ from enrich.logging import RichHandler
✗ from rich.logging import RichHandler
The `enrich` RichHandler provides an alternative logging handler, notably with soft-wrapping behavior, differing from the standard `rich` handler.

This quickstart demonstrates key features of the `enrich` library: a `Console` instance configured to redirect `sys.stdout` and capture output, another `Console` instance with implicit soft-wrapping enabled for print statements, and the `RichHandler` configured for soft-wrapping in standard Python logging.

import logging from enrich.console import Console from enrich.logging import RichHandler import sys # Example 1: Console with redirect support console_redirect = Console(redirect=True, record=True) original_stdout = sys.stdout sys.stdout = console_redirect.fileproxy print("This output is redirected and recorded.") sys.stdout = original_stdout # Restore stdout # print(f"Captured output: {console_redirect.export_text()}") # Use this to see recorded text # Example 2: Console with implicit soft wrapping console_soft_wrap = Console(soft_wrap=True) console_soft_wrap.print("This is a very long line of text that will be soft-wrapped by the console instance, ensuring it fits within any terminal width without explicit print arguments.") # Example 3: Soft-wrapping logger FORMAT = "%(message)s" logging.basicConfig( level="INFO", format=FORMAT, handlers=[RichHandler(soft_wrap=True)] ) log = logging.getLogger("my_app") log.info("This log message will also be soft-wrapped.") log.info("Another long message demonstrating the soft-wrapping logger functionality.")
Debug
Known issues
breakingFuture versions (v1.3.0+) will require Python 3.9 or newer. Version 1.2.7 (and earlier) supports Python 3.6+.
fix
Ensure your project uses Python 3.9 or higher when upgrading to `enrich` version 1.3.0 or later. For current versions (1.2.x), Python 3.6+ is sufficient.
affects: >=1.3.0
gotchaThe `Console` and `RichHandler` classes from `enrich` are distinct from their `rich` counterparts. Using `from rich.console import Console` will *not* provide the `enrich`-specific features like `redirect` or `soft_wrap` parameters.
fix
Always import `Console` and `RichHandler` from `enrich.console` and `enrich.logging` respectively, to access the extended functionality.
affects: All versions
gotchaThe `enrich` library is built upon `rich`, and breaking changes or incompatibilities in `rich` itself can affect `enrich` users. Specific versions of `enrich` might pin compatible `rich` versions.
fix
Refer to `enrich`'s release notes (e.g., 'Avoid incompatible version of rich' in v1.2.4) and its `pyproject.toml` or `setup.py` for exact `rich` version compatibility. Upgrade `rich` cautiously or allow `enrich` to manage its `rich` dependency.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'enrich'
The 'enrich' library is not installed in the current Python environment, or the environment where the code is being run does not have access to the installed library.
fix
Install the library using pip: `pip install enrich`
TypeError: __init__() got an unexpected keyword argument 'redirect'
This error occurs when attempting to use the `redirect=True` argument with the standard `rich.console.Console` class, but this specific argument is an enhancement provided only by the `enrich.console.Console` class.
fix
Ensure you are importing and using the `Console` class from `enrich.console` instead of `rich.console`: `from enrich.console import Console`
TypeError: __init__() got an unexpected keyword argument 'soft_wrap'
This error arises when trying to pass the `soft_wrap=True` argument directly to the `rich.console.Console` constructor. Implicit soft wrapping in the `Console` constructor is a feature added by the `enrich` library.
fix
Import and use the `Console` class from `enrich.console` to leverage its soft-wrapping capabilities: `from enrich.console import Console`
TypeError: __init__() got an unexpected keyword argument 'soft_wrap'
The `enrich.logging.RichHandler` inherently provides soft-wrapping behavior by internally using an `enrich.console.Console` instance configured for it. Passing `soft_wrap` as an explicit argument to the `RichHandler` constructor is not supported.
fix
Remove the `soft_wrap` argument when initializing `enrich.logging.RichHandler`, as its soft-wrapping is managed internally. For example: `from enrich.logging import RichHandler; handler = RichHandler()`
Upgrade
Version history
1.2.7latest on PyPI · released Jan 10, 2022
Audit
Dependencies
richrequiredCore dependency; 'enrich' extends 'rich' functionality.
Agent activity
38 hits · last 30 days
node
34
OpenAI (training)
2
Amazon
1
Resources
enrich — pip install enrich · libregistry