Skip to main content

Richer

Table renderer for dataclass using Rich

Features

List Table

Display table from dataclasses

1_list_table.py

from rich.console import Console
from richer.table import ListTable

@dataclass
class Project:
    name: str
    star_count: int
    start_date: datetime

items = [
    Project('Vue', 156110, datetime.fromisoformat('2013-07-29T00:00:00')),
    Project('React', 142857, datetime.fromisoformat('2013-05-25T00:00:00')),
    Project('Angular', 57004, datetime.fromisoformat('2014-09-19T00:00:00'))
]

console = Console()
console.print(ListTable(items))
┌─────────┬────────────┬─────────────────────┐
│ NAME    │ STAR COUNT │ START DATE          │
├─────────┼────────────┼─────────────────────┤
│ Vue     │    156,110 │ 2013-07-29 00:00:00 │
│ React   │    142,857 │ 2013-05-25 00:00:00 │
│ Angular │     57,004 │ 2014-09-19 00:00:00 │
└─────────┴────────────┴─────────────────────┘

Column Manipulations

Display a table with custom columns

  • Justify
  • Sort
  • Hide/Show

1-1_column_manipulation.py

from rich.console import Console
from richer.table import Column, ListTable

table = ListTable(
    items,
    columns=[
        Column(name='star_count', order='asc', justify='right'),
        Column(name='start_date', visible=False)
    ]
)

console = Console()
console.print(table)
┌─────────┬──────────────┐
│ NAME    │ STAR COUNT ▲ │
├─────────┼──────────────┤
│ Angular │       57,004 │
│ React   │      142,857 │
│ Vue     │      156,110 │
└─────────┴──────────────┘

Property Table

Display table from a dataclass

2_property_table.py

from richer.table import PropertyTable

console.print(PropertyTable(item[0]))
┌────────────┬─────────────────────┐
│ NAME       │ Vue                 │
├────────────┼─────────────────────┤
│ STAR COUNT │ 156,110             │
├────────────┼─────────────────────┤
│ START DATE │ 2013-07-29 00:00:00 │
└────────────┴─────────────────────┘

Inner Table

Display inner table from a nested dataclass

3_inner_table.py

@dataclass
class Tag:
    name: str
    commit: str

@dataclass
class Project:
    name: str
    star_count: int
    start_date: datetime
    tags: List[Tag]

tags = [
    Tag('v17.0.0', '89b6109'),
    Tag('v16.0.0', '5c6ef40')
]

item = Project(
    'React',
    142857,
    datetime.fromisoformat('2013-05-25T00:00:00'),
    tags
)

console.print(PropertyTable(item))
┌────────────┬─────────────────────┐
│ NAME       │ React               │
├────────────┼─────────────────────┤
│ STAR COUNT │ 142,857             │
├────────────┼─────────────────────┤
│ START DATE │ 2013-05-25 00:00:00 │
├────────────┼─────────────────────┤
│ TAGS       │  NAME    │ COMMIT   │
│            │ ─────────┼───────── │
│            │  v17.0.0 │ 89b6109  │
│            │  v16.0.0 │ 5c6ef40  │
└────────────┴─────────────────────┘

Pagination a table

Paginate a table using curses

  • Press 'q' key to exit from interactive console.
  • Press 'right' key or 'page down' key to go to next page.
  • Press 'left' key or 'page up' key to go to previous page.

4_pagination.py

from richer.console import InteractiveConsole

@dataclass
class Row:
    id: int

items = [Row(r) for r in range(0, 100)]

console = InteractiveConsole(items)
console.print()
┌────┐
│ ID │
├────┤
│  0 │
│  1 │
│  2 │
│  3 │
│  4 │
│  5 │
│  6 │
│  7 │
│  8 │
│  9 │
│ 10 │
└────┘

ANSI Escape Text

Display ANSI Escape Text

It is useful to use rich by redirecting stdout and stderr

5_ansi_escape_text.py

from richer.text import AnsiEscapeText

console = Console()
text = '\x1b[1;32mSuccess\x1b[0m\n\x1b[1;31mFailure\x1b[0m'
console.print(AnsiEscapeText(text))

Success
Failure

Release files for richer 0.1.6

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

Built distribution (wheel)

Table of built distributions (wheels) for richer 0.1.6
File Interpreter ABI Platform
richer-0.1.6-py3-none-any.whl Python 3 none any Details

Release files / richer-0.1.6-py3-none-any.whl

Download URL richer-0.1.6-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1498ed7aeeaca6d5f446bf5ab2511322ba10a0a65921af2dc0f1c6b73c2bbc27
BLAKE2b-256 checksum
How to use checksums
b21113681de0e08f14f20005589c70658c90c0ec19aebc7900dfb5126fec697e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.6 This release

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1

1 release file

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