Rich Integration API¶
Integration with the Rich library for colorful output.
RichPrinter¶
pyreprint.integrations.rich.RichPrinter(console=None, force_terminal=False, width=None)
¶
Rich-enabled printer with enhanced formatting.
This class provides a printer that leverages Rich for colorful, formatted console output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console
|
Optional[Console]
|
Rich Console instance to use. |
None
|
force_terminal
|
bool
|
Force terminal output even if not a TTY. |
False
|
width
|
Optional[int]
|
Console width (None for auto-detect). |
None
|
Example
printer = RichPrinter() printer.print("Hello, [bold]World[/bold]!") printer.rule("Section") printer.panel("Important message", title="Notice")
Source code in pyreprint/integrations/rich.py
Functions¶
header(text, style='bold', rule_style='rule.line')
¶
Print a header with underline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Header text. |
required |
style
|
str
|
Style for the text. |
'bold'
|
rule_style
|
str
|
Style for the underline. |
'rule.line'
|
Source code in pyreprint/integrations/rich.py
panel(content, title=None, subtitle=None, border_style='blue', expand=True)
¶
Print content in a panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The panel content. |
required |
title
|
Optional[str]
|
Optional panel title. |
None
|
subtitle
|
Optional[str]
|
Optional panel subtitle. |
None
|
border_style
|
str
|
Style for the border. |
'blue'
|
expand
|
bool
|
Whether to expand to full width. |
True
|
Source code in pyreprint/integrations/rich.py
print(*args, sep=' ', end='\n', markup=True, highlight=True, **kwargs)
¶
Print with Rich formatting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Values to print. |
()
|
sep
|
str
|
Separator between values. |
' '
|
end
|
str
|
String to append at end. |
'\n'
|
markup
|
bool
|
Whether to parse Rich markup. |
True
|
highlight
|
bool
|
Whether to highlight syntax. |
True
|
**kwargs
|
Any
|
Additional arguments for Console.print. |
{}
|
Source code in pyreprint/integrations/rich.py
rule(title='', char='-', style='rule.line', align='center')
¶
Print a horizontal rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Optional title in the rule. |
''
|
char
|
str
|
Character for the line (Rich may override). |
'-'
|
style
|
str
|
Rich style for the rule. |
'rule.line'
|
align
|
str
|
Title alignment ('left', 'center', 'right'). |
'center'
|
Source code in pyreprint/integrations/rich.py
section(text, style='bold blue')
¶
Print a section with rules above and below.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Section text. |
required |
style
|
str
|
Style for the text. |
'bold blue'
|
Source code in pyreprint/integrations/rich.py
status(message, status_type='info')
¶
Print a status message with appropriate styling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
The status message. |
required |
status_type
|
str
|
Type of status ('info', 'success', 'warning', 'error'). |
'info'
|
Source code in pyreprint/integrations/rich.py
table(data, headers=None, title=None)
¶
Print data as a table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
list
|
List of rows (each row is a list of values). |
required |
headers
|
Optional[list]
|
Optional list of column headers. |
None
|
title
|
Optional[str]
|
Optional table title. |
None
|
Source code in pyreprint/integrations/rich.py
Functions¶
rprint¶
pyreprint.integrations.rich.rprint(*args, sep=' ', end='\n', file=None, markup=True, highlight=True, **kwargs)
¶
Rich-enabled print function.
A drop-in replacement for print() that uses Rich for formatting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Values to print. |
()
|
sep
|
str
|
Separator between values. |
' '
|
end
|
str
|
String to append at end. |
'\n'
|
file
|
Optional[TextIO]
|
Output file (uses Rich console if None). |
None
|
markup
|
bool
|
Whether to parse Rich markup. |
True
|
highlight
|
bool
|
Whether to highlight syntax. |
True
|
**kwargs
|
Any
|
Additional arguments for Console.print. |
{}
|
Example
rprint("[bold red]Error:[/bold red] Something went wrong") rprint("Processing...", style="italic")
Source code in pyreprint/integrations/rich.py
rule¶
pyreprint.integrations.rich.rule(title='', style='rule.line')
¶
Print a horizontal rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str
|
Optional title in the rule. |
''
|
style
|
str
|
Rich style for the rule. |
'rule.line'
|
Source code in pyreprint/integrations/rich.py
panel¶
pyreprint.integrations.rich.panel(content, title=None, border_style='blue')
¶
Print content in a panel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
The panel content. |
required |
title
|
Optional[str]
|
Optional panel title. |
None
|
border_style
|
str
|
Style for the border. |
'blue'
|
Source code in pyreprint/integrations/rich.py
PrettyPrint¶
pprint¶
pyreprint.integrations.pprint.pprint(obj, stream=None, indent=1, width=80, depth=None, compact=False, sort_dicts=True)
¶
Pretty print an object.
Enhanced wrapper around the standard pprint module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to print. |
required |
stream
|
Optional[TextIO]
|
Output stream (default: sys.stdout). |
None
|
indent
|
int
|
Indentation level for nested structures. |
1
|
width
|
int
|
Maximum line width. |
80
|
depth
|
Optional[int]
|
Maximum depth to print (None for unlimited). |
None
|
compact
|
bool
|
Use compact format for sequences. |
False
|
sort_dicts
|
bool
|
Sort dictionary keys. |
True
|
Example
pprint({"a": [1, 2, 3], "b": {"nested": "value"}}) {'a': [1, 2, 3], 'b': {'nested': 'value'}}
Source code in pyreprint/integrations/pprint.py
pformat¶
pyreprint.integrations.pprint.pformat(obj, indent=1, width=80, depth=None, compact=False, sort_dicts=True)
¶
Format an object as a pretty-printed string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to format. |
required |
indent
|
int
|
Indentation level for nested structures. |
1
|
width
|
int
|
Maximum line width. |
80
|
depth
|
Optional[int]
|
Maximum depth to print (None for unlimited). |
None
|
compact
|
bool
|
Use compact format for sequences. |
False
|
sort_dicts
|
bool
|
Sort dictionary keys. |
True
|
Returns:
| Type | Description |
|---|---|
str
|
Pretty-printed string representation. |
Example
s = pformat({"key": "value"}) print(s)
Source code in pyreprint/integrations/pprint.py
PrettyPrinter¶
pyreprint.integrations.pprint.PrettyPrinter(indent=1, width=80, depth=None, compact=False, sort_dicts=True, stream=None)
¶
Configurable pretty printer.
This class provides a reusable pretty printer with customizable settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int
|
Indentation level for nested structures. |
1
|
width
|
int
|
Maximum line width. |
80
|
depth
|
Optional[int]
|
Maximum depth to print (None for unlimited). |
None
|
compact
|
bool
|
Use compact format for sequences. |
False
|
sort_dicts
|
bool
|
Sort dictionary keys. |
True
|
stream
|
Optional[TextIO]
|
Default output stream. |
None
|
Example
pp = PrettyPrinter(indent=2, width=60) pp.pprint({"a": [1, 2, 3]})
Source code in pyreprint/integrations/pprint.py
Functions¶
__call__(obj)
¶
Pretty print an object (shortcut for pprint).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to print. |
required |
isreadable(obj)
¶
Check if object repr is readable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if repr is readable Python code. |
isrecursive(obj)
¶
Check if object has recursive reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if object has recursive reference. |
pformat(obj)
¶
Format an object as a pretty-printed string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Object to format. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Pretty-printed string representation. |