rich-string-builder
Text preprocessor for building strings for the rich library
Background
This came about because I was annoyed at the way we needed to insert text into rich to make it reflect our intended stylistic choices. Take the following example:
console.print(
f"Subnet: [{COLOR_PALETTE['GENERAL']['SUBHEADING']}]{netuid_}[/{COLOR_PALETTE['GENERAL']['SUBHEADING']}] "
f"Stake:\n"
f" [blue]{current_stake}[/blue] "
f":arrow_right: "[{COLOR_PALETTE['STAKE']['STAKE_AMOUNT']}]{new_stake}\n"
)
With this library, it's a bit more readable as:
console.print(
rs.str(
"Subnet: ", rs.GENERAL.SUBHEADING(netuid_),
" Stake:\n ",
rs.c.blue(current_stake),
" :arrow_right: ", rs.STAKE.STAKE_AMOUNT(new_stake, "\n")
)
)
The ideas are largely derived from Tailwind and other utility-style frameworks/libraries.
Current State
Currently this is just proof of concept. I will likely add to this over time.
Examples
See examples directory for examples of using this.
One of the fundamental aspects of this library is the ability to preload your own custom styles from a dictionary, like so:
from rich.console import Console
from rich_string_builder.string_builder import RichStyles
console = Console()
my_styles = {
"alert": "blink yellow",
"headers": {
"main": "bold",
"sub": "#4196D6"
}
}
rs = RichStyles(my_styles)
console.print(rs.custom.alert("WARNING!")) # '[blink yellow]WARNING![/blink yellow]'
Though you are able to combine these styles ad-hoc:
bright_blue = rs.Styles.bright + rs.Colors.blue
console.print(bright_blue("Coldkey")) # '[bright blue]Coldkey[/bright blue]'
Say you have a complicated custom style, and you wish to only remove an element or two and reuse it:
my_styles = {
"foo": "blink bright yellow"
}
rs = RichStyles(my_styles)
console.print((rs.custom.foo - "blink")("Hello!")) # '[bright yellow]Hello![/bright yellow]'
# or define a new type:
bar = rs.custom.foo - "blink"
console.print(bar("Hello!")) # '[bright yellow]Hello![/bright yellow]'
Who is this for?
I am personally colourblind. It's nice to have someone who is not colourblind define a colour palette, and I simply build from this. While colourblind people are not the only intended users, I think it will help them (us) substantially in terms of readability of the styles. It's also very helpful for keeping easier track of your styles and reusability.
Metadata
Release files for rich-string-builder 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rich_string_builder-0.0.1.tar.gz | 4.9 kB | With provenance | Details for rich_string_builder-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rich_string_builder-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for rich_string_builder-0.0.1-py3-none-any.whl |
Total release size: 9.9 kB
Release files / rich_string_builder-0.0.1.tar.gz
| Download URL | rich_string_builder-0.0.1.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
861da0e09ee1ded315660aa132ae671505ae89db7dd9f9941c12f11edb9aafc5
|
|
BLAKE2b-256 checksum How to use checksums |
3d2ed2b9b288e068c855c05bbe24085e841af750838d00e31cbadb8513d9a049
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2025.
Transparency logRelease files / rich_string_builder-0.0.1-py3-none-any.whl
| Download URL | rich_string_builder-0.0.1-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d5292157a32b80cb3d0c6c9cb0954cbcb2966f0a4bc834354329b8492ce30622
|
|
BLAKE2b-256 checksum How to use checksums |
af7393e25124e33e2216585343d384f42d4afc4a7a78f04a3c89b0b4320dd1f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2025.
Transparency logSecurity for rich-string-builder 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for rich_string_builder-0.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 15, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.