A simple, zero-dependency package for adding ANSI color and style to terminal text.
Project description
PyAnsiWrap 🎨
A simple, zero-dependency Python class for adding color and style to your terminal text.
Ansiwrap provides a clean, fluent API to make your command-line applications more readable and visually appealing. It works on any terminal that supports ANSI escape codes (like most Linux, macOS, and modern Windows terminals).
Key Features
- Zero Dependencies: Pure Python, no external packages needed.
- Simple API: An intuitive, easy-to-learn set of static methods.
- Flexible Styling: Supports foreground/background colors, bold, underline, reverse, and more.
- Case-Insensitive: Color names can be red, RED, or Red.
- Global Control: Easily enable or disable all styling with a single command.
- Pipe-Aware: Automatically disables color when output is redirected to a file.
Installation
Install Ansiwrap directly from pip:
pip install pyansiwrap
Quick Start
Ansiwrap is designed to be straightforward. You can style a specific piece of text or apply a style to a whole block.
Styling a single string
This is the most common use case. The style is automatically applied and reset.
from pyansiwrap import Ansiwrap
# --- Foreground Colors ---
print("Status:", Ansiwrap.fg("green", "SUCCESS", bold=True))
print("Error:", Ansiwrap.fg("red", "File not found."))
# --- Background Colors ---
print(Ansiwrap.bg("yellow", Ansiwrap.fg("black", " WARNING ")))
# --- Other Styles ---
print("Task:", Ansiwrap.strikethrough("Review documents"), "(Complete)")
print("Selection:", Ansiwrap.reverse(" Menu Item 1 "))
Styling a block of text
Use the start_* methods to begin a style and reset() to end it.
from pyansiwrap import Ansiwrap
# Combine start codes by adding them together
print(Ansiwrap.start_fg("cyan") + Ansiwrap.start_underline(), end="")
print("System Log")
print("----------")
print("All systems are operating normally.")
# Return to the default terminal style
print(Ansiwrap.reset(), "Log finished.")
API Reference
All methods are static and can be called directly on the Ansiwrap class.
Wrapper methods
These methods style a specific text string and automatically append a reset code.
Ansiwrap.fg(color_name, text, bold=False): Styles foreground color.Ansiwrap.bg(color_name, text): Styles background color.Ansiwrap.underline(text)Ansiwrap.reverse(text)Ansiwrap.conceal(text)Ansiwrap.strikethrough(text)
Starter methods
These methods return only the opening ANSI code to start a persistent style.
Ansiwrap.start_fg(color_name, bold=False)Ansiwrap.start_bg(color_name)Ansiwrap.start_underline()Ansiwrap.start_reverse()Ansiwrap.start_conceal()Ansiwrap.start_strikethrough()
Global controls
Ansiwrap.enable(): Globally enables all styling.Ansiwrap.disable(): Globally disables all styling.Ansiwrap.reset(): Returns the code to reset all active styles.
Cross platform support
Ansiwrap works out-of-the-box on modern terminals. For compatibility with the legacy Windows cmd.exe, you can use it alongside the colorama library.
Initialize colorama at the start of your script to get the best of both worlds: colorama's robust Windows support and Ansiwrap's clean API.
import colorama
from pyansiwrap import Ansiwrap
# Let colorama handle Windows compatibility
colorama.init()
# Now use Ansiwrap's API as usual
print(Ansiwrap.fg("magenta", "This will work everywhere!"))
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 Distribution
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 pyansiwrap-1.0.0.tar.gz.
File metadata
- Download URL: pyansiwrap-1.0.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bff833cab43dacd0cf0ca488a93e5583759b721370ef3f9de9963c0faad52c1b
|
|
| MD5 |
83d6ea97d942a93954b1c1bfdd6c3229
|
|
| BLAKE2b-256 |
bb75958defdcc2210753db9b1b9c04203af0b514235c158ef36868d53bc9359a
|
File details
Details for the file pyansiwrap-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pyansiwrap-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7121a6f6aa8e8b8e4372dca0a3c5036d065532c668ffd8c109f092648a4982f
|
|
| MD5 |
36c2924ca4b02e9f15dea55671e201b6
|
|
| BLAKE2b-256 |
174957bf5fdb1b3ff435f940d2a6c0b76ba09a31c7482948297641f2b061e147
|