Skip to main content

Fluent ANSI-styled strings for Python.

Project description

sgroove

sgroove is a Python library for styling terminal output using ANSI escape sequences. It provides a fluent interface and integrates with Python's f-string formatting.

This started as a small personal project to explore the __format__-Dunder-method but might be useful for someone else, too.

Features

sgroove provides a fluent interface that lets you build up formatting step by step by chaining style calls, which keeps even more complex combinations readable and easy to reuse. It also integrates with Python’s f-string formatting so you can apply styles inline via semicolon-separated format specifiers, making it convenient to style output without wrapping everything in separate function calls.

Supported Colors

For colors, it supports the full range of common terminal options: the 8 standard ANSI colors with bright variants for quick, named styling, the 256-color ANSI palette for finer-grained choices, and 24-bit TrueColor (RGB) for exact color control when your terminal supports it.

Name Bright Variant
black bright_black
red bright_red
green bright_green
yellow bright_yellow
blue bright_blue
magenta bright_magenta
cyan bright_cyan
white bright_white

Supported Styles

In addition to colors, it includes widely used text modifiers—such as bold, italic, and underline—so you can highlight headings, warnings, and status messages consistently in CLI output.

Specifier Description
bold Bold or increased intensity
faint Decreased intensity
italic Italic font
underlined Underlined text
blinking Blinking text
crossed_out Strikethrough
framed Framed text
encircled Encircled text
overlined Overlined text

Examples

Fluent Interface

The fluent interface allows you to build styles by chaining method calls on an AnsiStr object.

from sgroove import S

# Simple red text
print(S("Hello").fg("red"))

# Bold and green background
print(S("Success").bold().bg("green"))

# Using RGB colors
print(S("TrueColor").rgb(255, 165, 0)) # Orange

Format Version

sgroove objects can be styled directly within f-strings using the format specifier. Multiple styles can be combined using semicolons.

from sgroove import S

text = S("Hello World!")

# Applying basic colors and styles
print(f"{text:blue;bold;underlined}")

# Using RGB in f-strings
print(f"{text:rgb(0, 255, 128)}")

# Combining named colors and custom RGB background
print(f"{text:white;bg_rgb(50, 50, 50)}")

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

sgroove-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

sgroove-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file sgroove-0.1.0.tar.gz.

File metadata

  • Download URL: sgroove-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sgroove-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d929b1ffebbbab550e14d71f99d98d5c134009a09b87dcde728340b83f9f14e3
MD5 3aa6e6e37d3e492e45a7848c023709c0
BLAKE2b-256 883ac3927a253526a8daefa9c7fbe11c022de71b154225c04cd0c62ac7b0cdac

See more details on using hashes here.

File details

Details for the file sgroove-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sgroove-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for sgroove-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b88eadc3abcea314dec9fbcb8608248a8cb7af744eab96ee6e0efdca548ad1ec
MD5 cd2bb7ba8c170ff66dd2fedef4c1cb8c
BLAKE2b-256 490da6da37dbb74307d03470d8051b98206da01a57826082171f83a8de9ccb17

See more details on using hashes here.

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