Sty

Latest version: v1.0.6

Safety actively analyzes 723158 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 3

1.0.0beta.9

I ran a bunch of performance tests on sty and I realized, that attribute access performance was unnecessarily bad. I figured that this was mainly due to the customization API, being somewhat complicated internally. The main goal of this release was to improve performance and simplify the customization API.

I think this brings us close to `v1.0.0`.

**Highlights**
* Increase access performance (a lot!)
* Simplify customiziation API
* Better linter compatibility (mypy, pylint, etc.)
* Move documentation from gitub README to sphinx page.
* Add `as_dict`, `as_namedtuple`, `copy` methods.
* Improve tests


Breaking changes

The customization API was rewritten. Please refer to the docs: https://feluxe.github.io/sty/docs/customizing.html

1.0.0beta.8

No breaking changes with this release.

You can now set multiple style rules on a single attribute

This works now:

python
fg.green_ul = Rule(Render.sgr, 32), Rule(Render.sgr, 4)
fg.red_i = Rule(Render.sgr, 31), ef.i
fg.blue_b = fg.blue + ef.b


Same for `set_rule`:

python
fg.set_rule('teal_b', (Rule(Render.eightbit_fg, 51), Rule(Render.sgr, 1)))
fg.set_rule('green_i', (fg.green, ef.i))
fg.set_rule('red_u', (Rule(Render.sgr, 31), ef.underl))

1.0.0beta.7

This release comes with a lot of changes, including a complete rewrite of the `Base` class and a rework of the Customization API. From now on you can mute/unmute styles as well.

**Highlights**
* Rework of Customization API
* Rework of the Base class.
* New Rule type for assigning rules to attributes.
* New Render enum storing render-function names.
* New way of assigning renderers and special call functions in the register-class definition.
* Ability to replace/add render-functions for register-objects
* Ability to mute/unmute register-objects.

Render-functions moved

The default render functions moved from `sty.renderer` to `sty.renderfunc`.

Changes within the customization API

Before `Beta 7` new rules were assigned like this:

python
from sty import fg

Direct attribute assignment
fg.orange = ('rgb', (255, 150, 50))

Attribute assignment via method
fg.set('my_color', 'eightbit', 51)

Since `Beta 7` you do it like this:

python
from sty import fg, Rule, Render

Direct attribute assignment
fg.orange = Rule(Render.rgb_fg, 255, 150, 50)

Attribute assignment via method
fg.set_rule('my_color', Rule(Render.eightbit_fg, 51))


You can see there are a couple of changes.

`set` method renamed to `set_rule`
`fg.set(..` is now `fg.set_rule(...`

The `Rule` type
We now use the `Rule` type (see example above) to set new styling/formatting rules for attributes. This makes for a cleaner `Base` class and a more structured API.

**The `Render` enum**
There is a new `Render` enum (see example above), which provides the renderer names. That means you can select a renderer via the `Render` enum:

python
Rule(Render.rgb_fg, 10, 20, 30)


The old style of selecting render functions by string still works as well:

python
Rule('rgb_fg', 10, 20, 30)


New register-class definition

Before `Beta 7` you could extend the default register classes like this:

python
from sty.register import FgRegister

Extend default Fg register.
class MyFgRegister(FgRegister):

Set a custom render-function
def custom_rgb_fg(self, *args):
return my_custom_rgb_fg_func(*args)

Set render-function for rgb call.
def _rgb_call(self, *args):
return my_custom_rgb_fg_func(*args)

black = ('sgr', 31)
red = ('sgr', 34)
orange = ('custom_rgb_fg', (255, 128, 0))
...


In `Beta 7` you do it like this:

python
import sty
from sty import FgRegister, Rule, Render

Extend the enum with the name of your new render-funtion.
class Render(sty.Render):
custom_rgb_fg = 'custom_rgb_fg'


Extend default Fg register.
class MyFgRegister(FgRegister):

Set a custom render-function
def __init__(self):
super().__init__() Call super to apply render-functions from parent FgRegister.
self.set_renderer(Render.custom_rgb_fg, my_custom_rgb_fg)

Set render-function for rgb call.
rgb_call = Rule(Render.rgb_fg)

black = Rule(Render.sgr, 31)
red = Rule(Render.sgr, 34)
orange = Rule(Render.custom_rgb_bg, 255, 128, 0)
...

As you see in the example above, they way we assign render-functions and the way we set render-functions for the special call methods has changed.

I suggest adding the name of the new renderer to the `Render` enum as shown above.

The new `set_renderer` method

You can now add/change render-functions for each register-object:

python
from sty import fg, Render

def my_custom_renderfunc():
...

fg.set_renderer(Render.rgb_fg, my_custom_renderfunc)



Muting / Silencing / Disabling formatting

This is now possible.

The `mute` and `unmute` methods

Sometimes its useful to disable the formatting for a register-object. You can do so by invoking the `mute` and `unmute` methods:

python
a = fg.red + 'This text is red.' + fg.rs

fg.mute()

b = fg.red + 'This text is NOT red.' + fg.rs

fg.unmute()

c = fg.red + 'This text is red.' + fg.rs


The `mute` and `unmute` batch functions

If you want to mute multiple register-objects at the same time you can use the `mute` and `unmute` functions that you find in `sty.mute`, `sty.unmute`:

python
from sty import fg, bg, ef, rs, mute, unmute

a1 = fg.red + 'This text is red.' + fg.rs
a2 = bg.red + 'This bg is red.' + bg.rs
a3 = ef.italic + 'This text is italic' + ef.rs

mute(fg, bg, ef, rs)

b1 = fg.red + 'This text is NOT red.' + fg.rs
b2 = bg.red + 'This bg is NOT red.' + bg.rs
b3 = ef.italic + 'This text is NOT italic' + ef.rs

unmute(fg, bg, ef, rs)

c1 = fg.red + 'This text is red.' + fg.rs
c2 = bg.red + 'This bg is red.' + bg.rs
c3 = ef.italic + 'This text is italic' + ef.rs

1.0.0beta.6

New effect names

These effects were renamed:

`faint` is now `dim`
`conceal` is now `hidden`
`reverse` is now `inverse`
`blink_fast` is now `blink`
`underline` is now `underl`

Drop blink_fast

Blink fast doesn't seem to be supported by most modern terminals. It was dropped for a cleaner api and possible unwanted side-effects.

Merge resetters for bold and dim

Fixes: 3

It turns out that most terminal use the same reset sequence for both `bold` and `dim`. That means `rs.bold` and `rs.dim` have to be merged into `rs.bold_dim` and `rs.dim_bold`. This sucks, but since that's how terminals do it, I don't see a better way to solve this in `sty`.

That measn `rs.bold`, `rs.b`, `rs.dim` (formaly `rs.faint`) were dropped in favor of `rs.bold_dim` and `rs.dim_bold`.

Page 3 of 3

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.