Registry / observability / sty
library1.0.6pypypi✓ verified 85d ago

Sty is a Python library that provides a simple, customizable, and performant string styling markup for terminal output, decoupled from specific color palettes and terminal implementations. It supports 3/4bit, 8bit, and 24bit (truecolor/RGB) colors, as well as effects like bold, italic, and underline. Currently at version 1.0.6, Sty follows semantic versioning and aims to maintain backward compatibility for 1.x.x releases after 1.0.0. It has no external dependencies and is actively maintained.

pip install sty
INSTALL
IMPORT
SIG · STY
S
sty
observabilitypythonv1.0.6
Install
1.5s avg
Import
15ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.016s · 17.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.5s · import 0.014s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fg, bg, ef, rs
from sty import fg, bg, ef, rs
Importing style objects directly is the recommended and most common pattern for convenient access to foreground, background, effects, and reset registers.

This quickstart demonstrates how to import and apply various foreground and background colors, as well as text effects. It shows examples for standard, 8-bit, and 24-bit RGB colors, and how to combine and reset styles using the provided register objects (`fg`, `bg`, `ef`, `rs`).

from sty import fg, bg, ef, rs # Basic colors print(fg.red + 'This is red text!' + fg.rs) print(bg.blue + 'This has a blue background!' + bg.rs) # Effects print(ef.bold + 'This is bold text' + ef.rs) print(ef.italic + 'This is italic text' + ef.rs) # 8-bit colors print(fg(201) + 'This is pink text using 8bit colors' + fg.rs) # 24-bit (RGB) colors print(fg(255, 10, 10) + 'This is red text using 24bit colors.' + fg.rs) # Combine styles print(fg.green + bg.yellow + ef.bold + 'Green text on yellow background, bold!' + rs.all)
Debug
Known issues
breakingMethods `.set_style()` and `.get_style()` were removed in v1.0.0-rc.1. They were deprecated in v1.0.0-beta.12. Using these methods in v1.0.0 or later will result in an AttributeError.
fix
Customize styling by directly assigning `Rule` objects to the registers (e.g., `fg.red = Rule(Render.rgb_fg, 255, 0, 0)`). Refer to the official documentation for current customization patterns.
affects: >=1.0.0
breakingThe reset register attribute `sty.rs.rs` was renamed to `sty.rs.ef` in v1.0.0-rc.2 due to a typo fix. Code using the old `sty.rs.rs` will fail with an AttributeError in subsequent versions.
fix
Update all instances of `sty.rs.rs` to `sty.rs.ef` to correctly apply the reset effect. The `rs.all` property can be used to reset all styles simultaneously.
affects: >=1.0.0-rc.2
breakingThe grey color palette definitions were changed in v1.0.0-rc.0. If your application relies on specific grey values from pre-release versions, the visual output might differ.
fix
Review and adjust any custom grey color definitions or assumptions based on the new palette definitions. You can define custom colors using `Rule` and `Render` classes.
affects: >=1.0.0-rc.0
gotchaWhile `import sty` and then referencing `sty.fg`, `sty.bg`, etc., technically works, the idiomatic and recommended approach for convenience and better performance is to directly import the register objects: `from sty import fg, bg, ef, rs`.
fix
Adopt the direct import pattern: `from sty import fg, bg, ef, rs`. This makes your code cleaner and aligns with the library's design.
affects: All versions
Errors
Common errors & fixes
AttributeError: 'Register' object has no attribute 'set_style'
Attempting to use the `set_style()` method, which was removed in `sty` v1.0.0-rc.1.
fix
Instead of `register.set_style(...)`, directly assign `Rule` objects to define custom styles, e.g., `fg.custom_color = Rule(Render.rgb_fg, 100, 200, 50)`.
AttributeError: 'Reset' object has no attribute 'rs'
Attempting to use the `sty.rs.rs` attribute after it was renamed to `sty.rs.ef` in `sty` v1.0.0-rc.2.
fix
Change `sty.rs.rs` to `sty.rs.ef` or use `rs.all` to reset all styles. For example, `print(fg.red + 'text' + rs.ef)` or `print(fg.red + 'text' + rs.all)`.
ModuleNotFoundError: No module named 'sty.lib'
Trying to import internal modules like `sty.lib` directly. These are not part of the public API and their structure can change.
fix
Always import public symbols directly from the `sty` package, e.g., `from sty import fg, bg, ef, rs`. The `sty.lib` path is for internal use.
Upgrade
Version history
1.0.6latest on PyPI · released Nov 27, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
sty — pip install sty · libregistry