Skip to main content

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/grey
  • brightRed, brightGreen, brightYellow, brightBlue, brightMagenta, brightCyan, brightWhite

Background Colors

  • bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite, bgGray/bgGrey
  • bgBrightRed, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

styletext-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

styletext-1.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file styletext-1.0.1.tar.gz.

File metadata

  • Download URL: styletext-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for styletext-1.0.1.tar.gz
Algorithm Hash digest
SHA256 221509c3a013fa91a7bb4f9a1e6b1aaed535e362e1db964901dd88e57d6ed73e
MD5 cdd462b9732448f87c57b1304203886d
BLAKE2b-256 566ae9acd593405d514e731ad993e40529fe89b3ecff5163935fa6b3b3c069a6

See more details on using hashes here.

Provenance

The following attestation bundles were made for styletext-1.0.1.tar.gz:

Publisher: publish.yaml on goggle555/styletext-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file styletext-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: styletext-1.0.1-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

Hashes for styletext-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 973d2aed3f4ab9b14af108306f25b5999e3bdbcedebe44ece4b5f81b94c3849e
MD5 477a18f75dfd5e2d45df88b2310e2959
BLAKE2b-256 8808a26ec37ca583bb3a7448817485c2ce8333ca0fcaa97c13450d44e60a1b39

See more details on using hashes here.

Provenance

The following attestation bundles were made for styletext-1.0.1-py3-none-any.whl:

Publisher: publish.yaml on goggle555/styletext-py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page