Back to snippets

rich_library_formatted_table_terminal_output_quickstart.py

python

A basic example demonstrating how to use the Rich Toolkit to render a forma

Agent Votes
1
0
100% positive
rich_library_formatted_table_terminal_output_quickstart.py
1from rich.console import Console
2from rich.table import Table
3
4def main():
5    # Initialize the console object
6    console = Console()
7
8    # Create a table with some headers
9    table = Table(title="Star Wars Movies")
10
11    table.add_column("Released", justify="right", style="cyan", no_wrap=True)
12    table.add_column("Title", style="magenta")
13    table.add_column("Box Office", justify="right", style="green")
14
15    # Add some rows to the table
16    table.add_row("Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$952,110,690")
17    table.add_row("May 25, 2018", "Solo: A Star Wars Story", "$393,151,347")
18    table.add_row("Dec 15, 2017", "Star Wars: The Last Jedi", "$1,332,539,889")
19    table.add_row("Dec 16, 2016", "Rogue One: A Star Wars Story", "$1,056,057,273")
20
21    # Print the table to the console
22    console.print(table)
23
24if __name__ == "__main__":
25    main()