A Python library providing a styleText function similar to Node.js util.styleText
Project description
styletext
A Python library providing a style_text() function similar to Node.js util.styleText(). Style your terminal output with ANSI escape codes using a simple, intuitive API.
Installation
uv add styletext
Or with pip:
pip install styletext
Or simply copy styletext.py to your project - zero dependencies required!
Usage
Basic Usage
from styletext import style_text
# Single style
print(style_text('red', 'Error message'))
print(style_text('green', 'Success message'))
# Multiple styles
print(style_text(['bold', 'blue'], 'Important text'))
print(style_text(['bgYellow', 'black', 'bold'], 'Warning'))
Chainable API (Bonus)
from styletext import styled
print(styled('Hello World').red.bold)
print(styled('Success!').green.underline)
print(styled('Warning').bgYellow.black)
Available Styles
Colors
black,red,green,yellow,blue,magenta,cyan,white,gray/greybrightRed,brightGreen,brightYellow,brightBlue,brightMagenta,brightCyan,brightWhite
Background Colors
bgBlack,bgRed,bgGreen,bgYellow,bgBlue,bgMagenta,bgCyan,bgWhite,bgGray/bgGreybgBrightRed,bgBrightGreen,bgBrightYellow,bgBrightBlue,bgBrightMagenta,bgBrightCyan,bgBrightWhite
Text Styles
bold,dim,italic,underline,blink,inverse,hidden,strikethrough
Examples
Log Messages
from styletext import style_text
# Success
print(style_text(['bold', 'green'], '✓') + ' Test passed')
# Error
print(style_text(['bold', 'red'], '✗') + ' Test failed')
# Info
print(style_text(['bgBlue', 'white', 'bold'], ' INFO ') + ' Server started')
# Warning
print(style_text(['bgYellow', 'black', 'bold'], ' WARN ') + ' Deprecated API')
# Error with details
error_msg = (
style_text(['bold', 'red'], 'Error: ') +
'Could not find file ' +
style_text(['italic', 'cyan'], 'config.json')
)
print(error_msg)
Progress Indicators
from styletext import styled
print(styled('⠋').cyan + ' Loading...')
print(styled('⠙').cyan + ' Processing...')
print(styled('✓').green.bold + ' Complete!')
Comparison with Node.js
Node.js:
import { styleText } from 'node:util';
console.log(styleText('red', 'Error!'));
console.log(styleText(['bold', 'blue'], 'Important'));
Python (this library):
from styletext import style_text
print(style_text('red', 'Error!'))
print(style_text(['bold', 'blue'], 'Important'))
Requirements
- Python 3.11+
- Zero external dependencies - just pure Python and ANSI escape codes!
License
MIT License
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
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 styletext-1.0.0.tar.gz.
File metadata
- Download URL: styletext-1.0.0.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79f4075a8ef37979496aea4164d08a258ca7b13ad1fc9cb4abc123f3237f5172
|
|
| MD5 |
57fc672dcf86d571f08fb58b99ae24cd
|
|
| BLAKE2b-256 |
a0e6ceb5f9186b31bc2e8022bb1b0621017e324d6783629513f7837054cb3431
|
Provenance
The following attestation bundles were made for styletext-1.0.0.tar.gz:
Publisher:
publish.yaml on goggle555/styletext-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
styletext-1.0.0.tar.gz -
Subject digest:
79f4075a8ef37979496aea4164d08a258ca7b13ad1fc9cb4abc123f3237f5172 - Sigstore transparency entry: 740313011
- Sigstore integration time:
-
Permalink:
goggle555/styletext-py@25316d2d0c877888dc1403fd8d536c95cdeea038 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/goggle555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@25316d2d0c877888dc1403fd8d536c95cdeea038 -
Trigger Event:
release
-
Statement type:
File details
Details for the file styletext-1.0.0-py3-none-any.whl.
File metadata
- Download URL: styletext-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9ba1965ac6af3b360d720ccf5454a22c2b9354301d4f33a33ccc3f8ffeb6308
|
|
| MD5 |
834c78f5b691c65b62111b8c05a6118a
|
|
| BLAKE2b-256 |
e7c3f7943d9e9677bcceee9e6d74f873733b9da3fad1dd8bda4f803668c33e8e
|
Provenance
The following attestation bundles were made for styletext-1.0.0-py3-none-any.whl:
Publisher:
publish.yaml on goggle555/styletext-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
styletext-1.0.0-py3-none-any.whl -
Subject digest:
c9ba1965ac6af3b360d720ccf5454a22c2b9354301d4f33a33ccc3f8ffeb6308 - Sigstore transparency entry: 740313016
- Sigstore integration time:
-
Permalink:
goggle555/styletext-py@25316d2d0c877888dc1403fd8d536c95cdeea038 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/goggle555
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@25316d2d0c877888dc1403fd8d536c95cdeea038 -
Trigger Event:
release
-
Statement type: