Skip to main content

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 rich to 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)

Source: github.com/cumulus13/rich-cleaner

Buy Me a Coffee

Donate via Ko-fi

Support me on Patreon

Metadata

Release files for rich-cleaner 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rich-cleaner 0.0.3
File Size Uploaded
rich_cleaner-0.0.3.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rich-cleaner 0.0.3
File Interpreter ABI Platform
rich_cleaner-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 11.7 kB

Release files / rich_cleaner-0.0.3.tar.gz

Download URL rich_cleaner-0.0.3.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
56e5286e51a8464f62c90922470ac5133e7e6bff25dfcfae45acf3de7d852ba5
BLAKE2b-256 checksum
How to use checksums
4574b0f57cb2ef1270ea36f8d305f3fd6407a3fa2adcf6a2d144a57277314b8d
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-0.0.3-py3-none-any.whl

Download URL rich_cleaner-0.0.3-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b5b4fa463aba8c3efc98b42a68d6f51078d188e811278fdcef77c5eca9aefe2
BLAKE2b-256 checksum
How to use checksums
014901e9b949155af9e8c76ad1b994e312faf1ad100f50058cd9071c112fd6bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

1.0.0

2 release files

This release

0.0.3 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page