Skip to content

Pretty Reference

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 Optional[Sequence[ColorType]]

Foreground gradient color stops.

None
bg_colors Optional[Sequence[ColorType]]

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

Scale factor controlling gradient repeats.

2.0
expand bool

Whether the gradient frame expands.

True
justify AlignMethod

Horizontal alignment.

'left'
vertical_justify VerticalAlignMethod

Vertical alignment.

'middle'
console Optional[Console]

Optional Rich console.

None
highlight_words Optional[HighlightWordsType]

Word highlight configuration.

None
highlight_regex Optional[HighlightRegexType]

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.
        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: Optional[Sequence[ColorType]] = None,
        bg_colors: Optional[Sequence[ColorType]] = None,
        rainbow: bool = False,
        hues: int = 5,
        repeat_scale: float = 2.0,
        expand: bool = True,
        justify: AlignMethod = "left",
        vertical_justify: VerticalAlignMethod = "middle",
        console: Optional[Console] = None,
        highlight_words: Optional[HighlightWordsType] = None,
        highlight_regex: Optional[HighlightRegexType] = 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=2.0, 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: Optional[Sequence[ColorType]] = None,
    bg_colors: Optional[Sequence[ColorType]] = None,
    rainbow: bool = False,
    hues: int = 5,
    repeat_scale: float = 2.0,
    expand: bool = True,
    justify: AlignMethod = "left",
    vertical_justify: VerticalAlignMethod = "middle",
    console: Optional[Console] = None,
    highlight_words: Optional[HighlightWordsType] = None,
    highlight_regex: Optional[HighlightRegexType] = 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,
    )