Skip to content

Pretty Reference

See the Pretty guide for usage examples.

Bases: Gradient

A Rich pretty-printer convenience constructor with gradient rendering.

Parameters:

Name Type Description Default
object_ Any

Object to pretty print.

required
highlighter Highlighter | None

Optional Rich highlighter.

None
indent_size int

Number of spaces per indent.

4
pretty_justify JustifyMethod | None

Justification used by Rich Pretty.

None
overflow OverflowMethod | None

Overflow handling used by Rich Pretty.

None
no_wrap bool | None

Whether to disable wrapping.

False
indent_guides bool

Whether to show indentation guides.

False
max_length int | None

Maximum container length before abbreviation.

None
max_string int | None

Maximum string length before truncation.

None
max_depth int | None

Maximum nested depth.

None
expand_all bool

Whether to expand all containers.

False
margin int

Width margin for expansion.

0
insert_line bool

Whether to insert a line before multiline output.

False
colors Sequence[ColorType] | None

Foreground gradient color stops.

None
bg_colors Sequence[ColorType] | None

Background gradient color stops.

None
rainbow bool

Whether to generate a rainbow palette.

False
hues int

Number of auto-generated hues.

5
repeat_scale float | None

Scale factor controlling gradient repeats. Defaults to None, which derives it from the color stops.

None
expand bool

Whether the gradient frame expands.

True
justify AlignMethod

Horizontal alignment.

'left'
vertical_justify VerticalAlignMethod

Vertical alignment.

'middle'
console Console | None

Optional Rich console.

None
highlight_words HighlightWordsType | None

Word highlight configuration.

None
highlight_regex HighlightRegexType | None

Regex highlight configuration.

None
Source code in src/rich_gradient/pretty.py
class Pretty(Gradient):
    """A Rich pretty-printer convenience constructor with gradient rendering.

    Args:
        object_: Object to pretty print.
        highlighter: Optional Rich highlighter.
        indent_size: Number of spaces per indent.
        pretty_justify: Justification used by Rich Pretty.
        overflow: Overflow handling used by Rich Pretty.
        no_wrap: Whether to disable wrapping.
        indent_guides: Whether to show indentation guides.
        max_length: Maximum container length before abbreviation.
        max_string: Maximum string length before truncation.
        max_depth: Maximum nested depth.
        expand_all: Whether to expand all containers.
        margin: Width margin for expansion.
        insert_line: Whether to insert a line before multiline output.
        colors: Foreground gradient color stops.
        bg_colors: Background gradient color stops.
        rainbow: Whether to generate a rainbow palette.
        hues: Number of auto-generated hues.
        repeat_scale: Scale factor controlling gradient repeats. Defaults to None,
            which derives it from the color stops.
        expand: Whether the gradient frame expands.
        justify: Horizontal alignment.
        vertical_justify: Vertical alignment.
        console: Optional Rich console.
        highlight_words: Word highlight configuration.
        highlight_regex: Regex highlight configuration.
    """

    def __init__(
        self,
        object_: Any,
        *,
        highlighter: Highlighter | None = None,
        indent_size: int = 4,
        pretty_justify: JustifyMethod | None = None,
        overflow: OverflowMethod | None = None,
        no_wrap: bool | None = False,
        indent_guides: bool = False,
        max_length: int | None = None,
        max_string: int | None = None,
        max_depth: int | None = None,
        expand_all: bool = False,
        margin: int = 0,
        insert_line: bool = False,
        colors: Sequence[ColorType] | None = None,
        bg_colors: Sequence[ColorType] | None = None,
        rainbow: bool = False,
        hues: int = 5,
        repeat_scale: float | None = None,
        expand: bool = True,
        justify: AlignMethod = "left",
        vertical_justify: VerticalAlignMethod = "middle",
        console: Console | None = None,
        highlight_words: HighlightWordsType | None = None,
        highlight_regex: HighlightRegexType | None = None,
    ) -> None:
        """Initialize a gradient-enabled Rich pretty-printer."""
        pretty = RichPretty(
            object_,
            highlighter=highlighter,
            indent_size=indent_size,
            justify=pretty_justify,
            overflow=overflow,
            no_wrap=no_wrap,
            indent_guides=indent_guides,
            max_length=max_length,
            max_string=max_string,
            max_depth=max_depth,
            expand_all=expand_all,
            margin=margin,
            insert_line=insert_line,
        )
        self._pretty = pretty
        super().__init__(
            pretty,
            colors=list(colors) if colors is not None else None,
            bg_colors=list(bg_colors) if bg_colors is not None else None,
            console=console,
            hues=hues,
            rainbow=rainbow,
            expand=expand,
            justify=justify,
            vertical_justify=vertical_justify,
            repeat_scale=repeat_scale,
            highlight_words=highlight_words,
            highlight_regex=highlight_regex,
        )

    @property
    def pretty(self) -> RichPretty:
        """Return the underlying Rich Pretty renderable."""
        return self._pretty

pretty property

Return the underlying Rich Pretty renderable.

__init__(object_, *, highlighter=None, indent_size=4, pretty_justify=None, overflow=None, no_wrap=False, indent_guides=False, max_length=None, max_string=None, max_depth=None, expand_all=False, margin=0, insert_line=False, colors=None, bg_colors=None, rainbow=False, hues=5, repeat_scale=None, expand=True, justify='left', vertical_justify='middle', console=None, highlight_words=None, highlight_regex=None)

Initialize a gradient-enabled Rich pretty-printer.

Source code in src/rich_gradient/pretty.py
def __init__(
    self,
    object_: Any,
    *,
    highlighter: Highlighter | None = None,
    indent_size: int = 4,
    pretty_justify: JustifyMethod | None = None,
    overflow: OverflowMethod | None = None,
    no_wrap: bool | None = False,
    indent_guides: bool = False,
    max_length: int | None = None,
    max_string: int | None = None,
    max_depth: int | None = None,
    expand_all: bool = False,
    margin: int = 0,
    insert_line: bool = False,
    colors: Sequence[ColorType] | None = None,
    bg_colors: Sequence[ColorType] | None = None,
    rainbow: bool = False,
    hues: int = 5,
    repeat_scale: float | None = None,
    expand: bool = True,
    justify: AlignMethod = "left",
    vertical_justify: VerticalAlignMethod = "middle",
    console: Console | None = None,
    highlight_words: HighlightWordsType | None = None,
    highlight_regex: HighlightRegexType | None = None,
) -> None:
    """Initialize a gradient-enabled Rich pretty-printer."""
    pretty = RichPretty(
        object_,
        highlighter=highlighter,
        indent_size=indent_size,
        justify=pretty_justify,
        overflow=overflow,
        no_wrap=no_wrap,
        indent_guides=indent_guides,
        max_length=max_length,
        max_string=max_string,
        max_depth=max_depth,
        expand_all=expand_all,
        margin=margin,
        insert_line=insert_line,
    )
    self._pretty = pretty
    super().__init__(
        pretty,
        colors=list(colors) if colors is not None else None,
        bg_colors=list(bg_colors) if bg_colors is not None else None,
        console=console,
        hues=hues,
        rainbow=rainbow,
        expand=expand,
        justify=justify,
        vertical_justify=vertical_justify,
        repeat_scale=repeat_scale,
        highlight_words=highlight_words,
        highlight_regex=highlight_regex,
    )