Rich Cleaner
Rich Cleaner is a zero-dependency, production-ready Python library and command-line interface (CLI) for stripping Rich markup formatting from text, strings, and files.
If you have logs or strings polluted with [bold red], [link=...], or [:smile:] and need pure, unformatted text without actually installing the heavy rich library, this tool handles it natively using a highly accurate state-machine parser.
Features
- Zero Dependencies: Built entirely on Python's standard library. Doesn't require
richto be installed. - 100% Native Parsing: Accurately strips color codes, style tags, links, and emojis while safely preserving escaped brackets (
[[ ]]). - Robust CLI: Clean files in-place or traverse directories recursively to scrub entire log folders.
- Dry-Run Mode: Preview which files would be modified before touching anything.
- Safe: Automatically skips binary files or files with non-UTF-8 encodings.
Installation
Install directly via pip:
pip install rich-cleaner
Or, if installing from the source repository:
git clone https://github.com/cumulus13/rich-cleaner.git
cd rich-cleaner
pip install -e .
# or
pip install git+https://github.com/cumulus13/rich-cleaner.git
Command-Line Usage (CLI)
Installing the package automatically registers the rich-cleaner command globally.
# Clean a single file in-place
rich-cleaner application.log
# See what would change in a directory without actually modifying files
rich-cleaner /var/logs/my_app --dry-run
# Recursively clean all .log files in a directory
rich-cleaner /var/logs/my_app --recursive --ext .log
# Quiet mode (only output errors)
rich-cleaner application.log --quiet
CLI Arguments
| Argument | Short | Description |
|---|---|---|
target |
Required. The target file or directory path to clean. | |
--recursive |
-r |
Process directories recursively. |
--dry-run |
-d |
Show what files would be modified without actually changing them. |
--ext |
-e |
Only process files with this extension (e.g., .log, .txt). |
--quiet |
-q |
Suppress standard output, only print errors. |
--help |
-h |
Show the help message and exit. |
Library Usage (Python API)
You can easily use the core parser inside your own Python projects.
Clean a Simple String
from rich_cleaner import RichCleaner
cleaner = RichCleaner()
dirty_text = "✓ github [bold #00FFFF]Forking[/] [bold #FFAA00]repo[/] [bold #00FFFF]Successfully[/]"
clean_text = cleaner.clean_text(dirty_text)
print(clean_text)
# Output: ✓ github Forking repo Successfully
Clean a File Programmatically
from pathlib import Path
from rich_cleaner import RichCleaner
cleaner = RichCleaner()
target_file = Path("app_output.txt")
# Cleans the file in-place. Returns True if modifications were made.
was_modified = cleaner.clean_file(target_file)
Edge Cases Handled
The parser behaves exactly like Rich's internal syntax engine. It correctly parses and handles:
- Single tags:
[bold],[red] - Multi-word tags:
[bold red on black] - Hex & RGB codes:
[#00FFFF],[rgb(255,0,0)] - Closing tags:
[/],[/bold] - Hyperlinks:
[link=https://example.com]Click Here[/link] - Emojis:
[:smile:] - Escaped brackets (leaves them intact):
[[Not a tag]]->[Not a tag]
👤 Author & License
Author: Hadi Cahyadi (cumulus13@gmail.com)
Metadata
Release files for rich-cleaner 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rich_cleaner-1.0.0.tar.gz | 5.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rich_cleaner-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / rich_cleaner-1.0.0.tar.gz
| Download URL | rich_cleaner-1.0.0.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
606b68dda4dc4412c52d4a53765d07a48900d04c5150a54f1c3d8d51b53f0510
|
|
BLAKE2b-256 checksum How to use checksums |
b3723881083884d18cd3dfdbbc1e83237e19d9ed1e8f19151f6a6d6d71bd7cf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|
Release files / rich_cleaner-1.0.0-py3-none-any.whl
| Download URL | rich_cleaner-1.0.0-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ab41154c83ce99394f2436203f3a70ef8b8ba2ffec8ba55e484dfdb73a6d9082
|
|
BLAKE2b-256 checksum How to use checksums |
a9c81927d7788035bfcf12c759a31387079a2f0a959d0ea740eeccf3b4242549
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.4
|