rich.pretty¶
-
class
rich.pretty.
Node
(key_repr: str = '', value_repr: str = '', open_brace: str = '', close_brace: str = '', empty: str = '', last: bool = False, is_tuple: bool = False, children: Optional[List[rich.pretty.Node]] = None)[source]¶ A node in a repr tree. May be atomic or a container.
-
check_length
(start_length: int, max_length: int) → bool[source]¶ Check the length fits within a limit.
- Parameters
start_length (int) – Starting length of the line (indent, prefix, suffix).
max_length (int) – Maximum length.
- Returns
True if the node can be rendered within max length, otherwise False.
- Return type
bool
-
render
(max_width: int = 80, indent_size: int = 4, expand_all: bool = False) → str[source]¶ Render the node to a pretty repr.
- Parameters
max_width (int, optional) – Maximum width of the repr. Defaults to 80.
indent_size (int, optional) – Size of indents. Defaults to 4.
expand_all (bool, optional) – Expand all levels. Defaults to False.
- Returns
A repr string of the original object.
- Return type
str
-
property
separator
¶ Get separator between items.
-
-
class
rich.pretty.
Pretty
(_object: Any, highlighter: HighlighterType = None, *, indent_size: int = 4, justify: JustifyMethod = None, overflow: Optional[OverflowMethod] = None, no_wrap: Optional[bool] = False, indent_guides: bool = False, max_length: int = None, max_string: int = None, expand_all: bool = False, margin: int = 0, insert_line: bool = False)[source]¶ A rich renderable that pretty prints an object.
- Parameters
_object (Any) – An object to pretty print.
highlighter (HighlighterType, optional) – Highlighter object to apply to result, or None for ReprHighlighter. Defaults to None.
indent_size (int, optional) – Number of spaces in indent. Defaults to 4.
justify (JustifyMethod, optional) – Justify method, or None for default. Defaults to None.
overflow (OverflowMethod, optional) – Overflow method, or None for default. Defaults to None.
no_wrap (Optional[bool], optional) – Disable word wrapping. Defaults to False.
indent_guides (bool, optional) – Enable indentation guides. Defaults to False.
max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None.
max_string (int, optional) – Maximum length of string before truncating, or None to disable. Defaults to None.
expand_all (bool, optional) – Expand all containers. Defaults to False.
margin (int, optional) – Subtrace a margin from width to force containers to expand earlier. Defaults to 0.
insert_line (bool, optional) – Insert a new line if the output has multiple new lines. Defaults to False.
-
rich.pretty.
install
(console: Console = None, overflow: OverflowMethod = 'ignore', crop: bool = False, indent_guides: bool = False, max_length: int = None, max_string: int = None, expand_all: bool = False) → None[source]¶ Install automatic pretty printing in the Python REPL.
- Parameters
console (Console, optional) – Console instance or
None
to use global console. Defaults to None.overflow (Optional[OverflowMethod], optional) – Overflow method. Defaults to “ignore”.
crop (Optional[bool], optional) – Enable cropping of long lines. Defaults to False.
indent_guides (bool, optional) – Enable indentation guides. Defaults to False.
max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None.
max_string (int, optional) – Maximum length of string before truncating, or None to disable. Defaults to None.
expand_all (bool, optional) – Expand all containers. Defaults to False
-
rich.pretty.
is_expandable
(obj: Any) → bool[source]¶ Check if an object may be expanded by pretty print.
-
rich.pretty.
pprint
(_object: Any, *, console: Console = None, indent_guides: bool = True, max_length: int = None, max_string: int = None, expand_all: bool = False)[source]¶ A convenience function for pretty printing.
- Parameters
_object (Any) – Object to pretty print.
console (Console, optional) – Console instance, or None to use default. Defaults to None.
max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None.
max_string (int, optional) – Maximum length of strings before truncating, or None to disable. Defaults to None.
indent_guides (bool, optional) – Enable indentation guides. Defaults to True.
expand_all (bool, optional) – Expand all containers. Defaults to False.
-
rich.pretty.
pretty_repr
(_object: Any, *, max_width: int = 80, indent_size: int = 4, max_length: Optional[int] = None, max_string: Optional[int] = None, expand_all: bool = False) → str[source]¶ Prettify repr string by expanding on to new lines to fit within a given width.
- Parameters
_object (Any) – Object to repr.
max_width (int, optional) – Desired maximum width of repr string. Defaults to 80.
indent_size (int, optional) – Number of spaces to indent. Defaults to 4.
max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None.
max_string (int, optional) – Maximum length of string before truncating, or None to disable truncating. Defaults to None.
expand_all (bool, optional) – Expand all containers regardless of available width. Defaults to False.
- Returns
A possibly multi-line representation of the object.
- Return type
str
-
rich.pretty.
traverse
(_object: Any, max_length: Optional[int] = None, max_string: Optional[int] = None) → rich.pretty.Node[source]¶ Traverse object and generate a tree.
- Parameters
_object (Any) – Object to be traversed.
max_length (int, optional) – Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to None.
max_string (int, optional) – Maximum length of string before truncating, or None to disable truncating. Defaults to None.
- Returns
The root of a tree structure which can be used to render a pretty repr.
- Return type