Skip to main content

rich-struct

rich's print, with 25 themes (23 popular editor themes and two originals) and helpers for Markdown, HTML, JSON, YAML, XML, Python objects and tables (lists, numpy arrays, pandas DataFrames and Series).

pip install rich-struct          # add [yaml] to dump objects with print_yaml, [html] for print_html
from rich.markdown import Markdown
from rich.theme import Theme
from rich_struct import ThemeName, print, print_md, print_json, print_yaml, print_xml, print_obj, print_syntax, print_table, print_list, print_html

print("[bold]hello[/bold]", {"a": 1})                 # drop-in rich.print, Midnight Slate by default
print(Markdown("## Printing structs"), theme=ThemeName.DRACULA)

print_md("# Title\n\n```python\nprint('hi')\n```")
print_json({"a": [1, 2, None]}, theme="Nord")         # enum value as a string works too
print_yaml("a: 1\nb: [x, y]")
print_xml("<a><b c='d'/></a>")
print_html("<h1>Title</h1><p>Some <b>bold</b> text</p>")  # rendered, not its tags
print_obj(my_dataclass, theme=ThemeName.GITHUB_LIGHT)
print_syntax("SELECT 1", "sql")                       # any pygments lexer
print_table(df, title="Sales")                        # DataFrame, Series, numpy array, list...
print(df)                                             # arrays and frames become tables in print too
print_list(series, head_tail_only=True)               # [1, 2.5, 'text',  ...  98, 99]: list, array, Series

print_md("# Mine", theme=Theme({"markdown.h1": "bold magenta", "syntax.keyword": "red"}))

Every function takes theme=: a ThemeName, its string value, or a rich Theme. To change the theme for all of them at once, call set_default_theme("Dracula") (same accepted values; no argument resets to Midnight Slate). Passing None to any of them prints None (JSON: null) in the theme's colour for null values instead of failing. ThemeName.X.theme gives you the underlying rich Theme to use with your own Console.

Screenshots

One per kind of struct, each in a different theme. The demo notebook shows every kind in all 25 themes; open it in Jupyter or VS Code to see the colours.

Markdown — print_md, Midnight Slate (the default)

Markdown in the Midnight Slate theme

HTML — print_html, Dracula

HTML in the Dracula theme

JSON — print_json, Nord

JSON in the Nord theme

YAML — print_yaml, One Dark Pro

YAML in the One Dark Pro theme

XML — print_xml, GitHub Dark

XML in the GitHub Dark theme

Python objects — print_obj, Catppuccin Mocha

Python objects in the Catppuccin Mocha theme

Code — print_syntax, One Light

Code in the One Light theme

Lists — print_table, Catppuccin Latte

Lists in the Catppuccin Latte theme

Sequences — print_list with head_tail_only, Tokyo Night

A sequence in the Tokyo Night theme

NumPy arrays — print_table, Solarized Dark

NumPy arrays in the Solarized Dark theme

pandas DataFrames — print_table, GitHub Light

pandas DataFrames in the GitHub Light theme

pandas Series — print_table, Night Owl

pandas Series in the Night Owl theme

Tables

print_table(data, title=None, max_rows=20, max_cols=10) accepts:

  • pandas DataFrame and Series, numpy arrays of any dimension (more than 2: one table per slice)
  • lists of dicts (records), lists of lists (a grid), and any other sequence such as array.array or range (one column)

Numbers are right-aligned, floats in a column share their decimals, and missing values are dimmed. Long data shows its head and tail around a … gap, and columns that don't fit the terminal width go into the gap as well. to_table(data) returns the renderable instead of printing it. numpy and pandas are not dependencies.

Lists

print_list(data, wrap=True, head_tail_only=False, head_tail_size=100) prints a list, tuple, array.array, numpy array or pandas Series as one sequence: [123, 1444.555, 'Test text', 4345.666].

It wraps at the terminal width; wrap=False keeps it on one line. head_tail_only=True shows only the first and last head_tail_size elements, with a highlighted ... between them.

Themes

Dark Light
Tokyo Night GitHub Light
Dracula Solarized Light
One Dark Pro One Light
Monokai Catppuccin Latte
Nord Gruvbox Light
Gruvbox Dark Tokyo Night Light
Catppuccin Mocha Ayu Light
Solarized Dark Night Owl Light
GitHub Dark Light+
Night Owl Everforest Light
Winter is Coming Light Modern
Dark Modern Paper Frost
Midnight Slate (default)

Themes are built from each theme's colour palette, not ported token-by-token from the editor.

Output is painted on the theme's background across the full terminal width. Pass background=False to keep the terminal's own background; nothing is painted or padded when the output has no colour (e.g. piped to a file). A custom Theme gets a background by defining a background style, e.g. "background": "#c0caf5 on #1a1b26".

Code colours come from syntax.* styles (text, comment, keyword, string, number, function, type, tag, attribute, operator); a custom Theme may override any of them, and may set syntax.block (e.g. "on #111c2e") to shade code blocks inside Markdown, and repr.background to give print_obj output its own background.

Metadata

Release files for rich-struct 0.4.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rich-struct 0.4.3
File Size Uploaded
rich_struct-0.4.3.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rich-struct 0.4.3
File Interpreter ABI Platform
rich_struct-0.4.3-py3-none-any.whl Python 3 none any Details

Total release size: 33.8 kB

Release files / rich_struct-0.4.3.tar.gz

Download URL rich_struct-0.4.3.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f4ef9fdff3abe369ee9b19bd5b12780d472a7c869435db47996aa31112fabadf
BLAKE2b-256 checksum
How to use checksums
04fdc324341d71e7a291f003f2d39e843f816c53095613e82a4654453d5b9c48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / rich_struct-0.4.3-py3-none-any.whl

Download URL rich_struct-0.4.3-py3-none-any.whl
Size 15.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7046174565697b91ac333be22dc19d484c5d5c18288785b193ba5fc8d1cc46da
BLAKE2b-256 checksum
How to use checksums
364f38a87a3fe8c3067d77c7614779970b708953992ad022b1accaebbcb0300e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

0.5.0

2 release files

This release

0.4.3 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page