Debian Codegraph @

third_party/python/rich/rich-14.0.0.dist-info/METADATA

raw
1 Metadata-Version: 2.1
2 Name: rich
3 Version: 14.0.0
4 Summary: Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal
5 Home-page: https://github.com/Textualize/rich
6 License: MIT
7 Author: Will McGugan
8 Author-email: [email protected]
9 Requires-Python: >=3.8.0
10 Classifier: Development Status :: 5 - Production/Stable
11 Classifier: Environment :: Console
12 Classifier: Framework :: IPython
13 Classifier: Intended Audience :: Developers
14 Classifier: License :: OSI Approved :: MIT License
15 Classifier: Operating System :: MacOS
16 Classifier: Operating System :: Microsoft :: Windows
17 Classifier: Operating System :: POSIX :: Linux
18 Classifier: Programming Language :: Python :: 3
19 Classifier: Programming Language :: Python :: 3.8
20 Classifier: Programming Language :: Python :: 3.9
21 Classifier: Programming Language :: Python :: 3.10
22 Classifier: Programming Language :: Python :: 3.11
23 Classifier: Programming Language :: Python :: 3.12
24 Classifier: Programming Language :: Python :: 3.13
25 Classifier: Typing :: Typed
26 Provides-Extra: jupyter
27 Requires-Dist: ipywidgets (>=7.5.1,<9) ; extra == "jupyter"
28 Requires-Dist: markdown-it-py (>=2.2.0)
29 Requires-Dist: pygments (>=2.13.0,<3.0.0)
30 Requires-Dist: typing-extensions (>=4.0.0,<5.0) ; python_version < "3.11"
31 Project-URL: Documentation, https://rich.readthedocs.io/en/latest/
32 Description-Content-Type: text/markdown
33
34 [![Supported Python Versions](https://img.shields.io/pypi/pyversions/rich/13.2.0)](https://pypi.org/project/rich/) [![PyPI version](https://badge.fury.io/py/rich.svg)](https://badge.fury.io/py/rich)
35
36 [![Downloads](https://pepy.tech/badge/rich/month)](https://pepy.tech/project/rich)
37 [![codecov](https://img.shields.io/codecov/c/github/Textualize/rich?label=codecov&logo=codecov)](https://codecov.io/gh/Textualize/rich)
38 [![Rich blog](https://img.shields.io/badge/blog-rich%20news-yellowgreen)](https://www.willmcgugan.com/tag/rich/)
39 [![Twitter Follow](https://img.shields.io/twitter/follow/willmcgugan.svg?style=social)](https://twitter.com/willmcgugan)
40
41 ![Logo](https://github.com/textualize/rich/raw/master/imgs/logo.svg)
42
43 [English readme](https://github.com/textualize/rich/blob/master/README.md)
44 • [简体中文 readme](https://github.com/textualize/rich/blob/master/README.cn.md)
45 • [正體中文 readme](https://github.com/textualize/rich/blob/master/README.zh-tw.md)
46 • [Lengua española readme](https://github.com/textualize/rich/blob/master/README.es.md)
47 • [Deutsche readme](https://github.com/textualize/rich/blob/master/README.de.md)
48 • [Läs på svenska](https://github.com/textualize/rich/blob/master/README.sv.md)
49 • [日本語 readme](https://github.com/textualize/rich/blob/master/README.ja.md)
50 • [한국어 readme](https://github.com/textualize/rich/blob/master/README.kr.md)
51 • [Français readme](https://github.com/textualize/rich/blob/master/README.fr.md)
52 • [Schwizerdütsch readme](https://github.com/textualize/rich/blob/master/README.de-ch.md)
53 • [हिन्दी readme](https://github.com/textualize/rich/blob/master/README.hi.md)
54 • [Português brasileiro readme](https://github.com/textualize/rich/blob/master/README.pt-br.md)
55 • [Italian readme](https://github.com/textualize/rich/blob/master/README.it.md)
56 • [Русский readme](https://github.com/textualize/rich/blob/master/README.ru.md)
57 • [Indonesian readme](https://github.com/textualize/rich/blob/master/README.id.md)
58 • [فارسی readme](https://github.com/textualize/rich/blob/master/README.fa.md)
59 • [Türkçe readme](https://github.com/textualize/rich/blob/master/README.tr.md)
60 • [Polskie readme](https://github.com/textualize/rich/blob/master/README.pl.md)
61
62
63 Rich is a Python library for _rich_ text and beautiful formatting in the terminal.
64
65 The [Rich API](https://rich.readthedocs.io/en/latest/) makes it easy to add color and style to terminal output. Rich can also render pretty tables, progress bars, markdown, syntax highlighted source code, tracebacks, and more — out of the box.
66
67 ![Features](https://github.com/textualize/rich/raw/master/imgs/features.png)
68
69 For a video introduction to Rich see [calmcode.io](https://calmcode.io/rich/introduction.html) by [@fishnets88](https://twitter.com/fishnets88).
70
71 See what [people are saying about Rich](https://www.willmcgugan.com/blog/pages/post/rich-tweets/).
72
73 ## Compatibility
74
75 Rich works with Linux, macOS and Windows. True color / emoji works with new Windows Terminal, classic terminal is limited to 16 colors. Rich requires Python 3.8 or later.
76
77 Rich works with [Jupyter notebooks](https://jupyter.org/) with no additional configuration required.
78
79 ## Installing
80
81 Install with `pip` or your favorite PyPI package manager.
82
83 ```sh
84 python -m pip install rich
85 ```
86
87 Run the following to test Rich output on your terminal:
88
89 ```sh
90 python -m rich
91 ```
92
93 ## Rich Print
94
95 To effortlessly add rich output to your application, you can import the [rich print](https://rich.readthedocs.io/en/latest/introduction.html#quick-start) method, which has the same signature as the builtin Python function. Try this:
96
97 ```python
98 from rich import print
99
100 print("Hello, [bold magenta]World[/bold magenta]!", ":vampire:", locals())
101 ```
102
103 ![Hello World](https://github.com/textualize/rich/raw/master/imgs/print.png)
104
105 ## Rich REPL
106
107 Rich can be installed in the Python REPL, so that any data structures will be pretty printed and highlighted.
108
109 ```python
110 >>> from rich import pretty
111 >>> pretty.install()
112 ```
113
114 ![REPL](https://github.com/textualize/rich/raw/master/imgs/repl.png)
115
116 ## Using the Console
117
118 For more control over rich terminal content, import and construct a [Console](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console) object.
119
120 ```python
121 from rich.console import Console
122
123 console = Console()
124 ```
125
126 The Console object has a `print` method which has an intentionally similar interface to the builtin `print` function. Here's an example of use:
127
128 ```python
129 console.print("Hello", "World!")
130 ```
131
132 As you might expect, this will print `"Hello World!"` to the terminal. Note that unlike the builtin `print` function, Rich will word-wrap your text to fit within the terminal width.
133
134 There are a few ways of adding color and style to your output. You can set a style for the entire output by adding a `style` keyword argument. Here's an example:
135
136 ```python
137 console.print("Hello", "World!", style="bold red")
138 ```
139
140 The output will be something like the following:
141
142 ![Hello World](https://github.com/textualize/rich/raw/master/imgs/hello_world.png)
143
144 That's fine for styling a line of text at a time. For more finely grained styling, Rich renders a special markup which is similar in syntax to [bbcode](https://en.wikipedia.org/wiki/BBCode). Here's an example:
145
146 ```python
147 console.print("Where there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]way[/i].")
148 ```
149
150 ![Console Markup](https://github.com/textualize/rich/raw/master/imgs/where_there_is_a_will.png)
151
152 You can use a Console object to generate sophisticated output with minimal effort. See the [Console API](https://rich.readthedocs.io/en/latest/console.html) docs for details.
153
154 ## Rich Inspect
155
156 Rich has an [inspect](https://rich.readthedocs.io/en/latest/reference/init.html?highlight=inspect#rich.inspect) function which can produce a report on any Python object, such as class, instance, or builtin.
157
158 ```python
159 >>> my_list = ["foo", "bar"]
160 >>> from rich import inspect
161 >>> inspect(my_list, methods=True)
162 ```
163
164 ![Log](https://github.com/textualize/rich/raw/master/imgs/inspect.png)
165
166 See the [inspect docs](https://rich.readthedocs.io/en/latest/reference/init.html#rich.inspect) for details.
167
168 # Rich Library
169
170 Rich contains a number of builtin _renderables_ you can use to create elegant output in your CLI and help you debug your code.
171
172 Click the following headings for details:
173
174 <details>
175 <summary>Log</summary>
176
177 The Console object has a `log()` method which has a similar interface to `print()`, but also renders a column for the current time and the file and line which made the call. By default Rich will do syntax highlighting for Python structures and for repr strings. If you log a collection (i.e. a dict or a list) Rich will pretty print it so that it fits in the available space. Here's an example of some of these features.
178
179 ```python
180 from rich.console import Console
181 console = Console()
182
183 test_data = [
184 {"jsonrpc": "2.0", "method": "sum", "params": [None, 1, 2, 4, False, True], "id": "1",},
185 {"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
186 {"jsonrpc": "2.0", "method": "subtract", "params": [42, 23], "id": "2"},
187 ]
188
189 def test_log():
190 enabled = False
191 context = {
192 "foo": "bar",
193 }
194 movies = ["Deadpool", "Rise of the Skywalker"]
195 console.log("Hello from", console, "!")
196 console.log(test_data, log_locals=True)
197
198
199 test_log()
200 ```
201
202 The above produces the following output:
203
204 ![Log](https://github.com/textualize/rich/raw/master/imgs/log.png)
205
206 Note the `log_locals` argument, which outputs a table containing the local variables where the log method was called.
207
208 The log method could be used for logging to the terminal for long running applications such as servers, but is also a very nice debugging aid.
209
210 </details>
211 <details>
212 <summary>Logging Handler</summary>
213
214 You can also use the builtin [Handler class](https://rich.readthedocs.io/en/latest/logging.html) to format and colorize output from Python's logging module. Here's an example of the output:
215
216 ![Logging](https://github.com/textualize/rich/raw/master/imgs/logging.png)
217
218 </details>
219
220 <details>
221 <summary>Emoji</summary>
222
223 To insert an emoji in to console output place the name between two colons. Here's an example:
224
225 ```python
226 >>> console.print(":smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:")
227 😃 🧛 💩 👍 🦝
228 ```
229
230 Please use this feature wisely.
231
232 </details>
233
234 <details>
235 <summary>Tables</summary>
236
237 Rich can render flexible [tables](https://rich.readthedocs.io/en/latest/tables.html) with unicode box characters. There is a large variety of formatting options for borders, styles, cell alignment etc.
238
239 ![table movie](https://github.com/textualize/rich/raw/master/imgs/table_movie.gif)
240
241 The animation above was generated with [table_movie.py](https://github.com/textualize/rich/blob/master/examples/table_movie.py) in the examples directory.
242
243 Here's a simpler table example:
244
245 ```python
246 from rich.console import Console
247 from rich.table import Table
248
249 console = Console()
250
251 table = Table(show_header=True, header_style="bold magenta")
252 table.add_column("Date", style="dim", width=12)
253 table.add_column("Title")
254 table.add_column("Production Budget", justify="right")
255 table.add_column("Box Office", justify="right")
256 table.add_row(
257 "Dec 20, 2019", "Star Wars: The Rise of Skywalker", "$275,000,000", "$375,126,118"
258 )
259 table.add_row(
260 "May 25, 2018",
261 "[red]Solo[/red]: A Star Wars Story",
262 "$275,000,000",
263 "$393,151,347",
264 )
265 table.add_row(
266 "Dec 15, 2017",
267 "Star Wars Ep. VIII: The Last Jedi",
268 "$262,000,000",
269 "[bold]$1,332,539,889[/bold]",
270 )
271
272 console.print(table)
273 ```
274
275 This produces the following output:
276
277 ![table](https://github.com/textualize/rich/raw/master/imgs/table.png)
278
279 Note that console markup is rendered in the same way as `print()` and `log()`. In fact, anything that is renderable by Rich may be included in the headers / rows (even other tables).
280
281 The `Table` class is smart enough to resize columns to fit the available width of the terminal, wrapping text as required. Here's the same example, with the terminal made smaller than the table above:
282
283 ![table2](https://github.com/textualize/rich/raw/master/imgs/table2.png)
284
285 </details>
286
287 <details>
288 <summary>Progress Bars</summary>
289
290 Rich can render multiple flicker-free [progress](https://rich.readthedocs.io/en/latest/progress.html) bars to track long-running tasks.
291
292 For basic usage, wrap any sequence in the `track` function and iterate over the result. Here's an example:
293
294 ```python
295 from rich.progress import track
296
297 for step in track(range(100)):
298 do_step(step)
299 ```
300
301 It's not much harder to add multiple progress bars. Here's an example taken from the docs:
302
303 ![progress](https://github.com/textualize/rich/raw/master/imgs/progress.gif)
304
305 The columns may be configured to show any details you want. Built-in columns include percentage complete, file size, file speed, and time remaining. Here's another example showing a download in progress:
306
307 ![progress](https://github.com/textualize/rich/raw/master/imgs/downloader.gif)
308
309 To try this out yourself, see [examples/downloader.py](https://github.com/textualize/rich/blob/master/examples/downloader.py) which can download multiple URLs simultaneously while displaying progress.
310
311 </details>
312
313 <details>
314 <summary>Status</summary>
315
316 For situations where it is hard to calculate progress, you can use the [status](https://rich.readthedocs.io/en/latest/reference/console.html#rich.console.Console.status) method which will display a 'spinner' animation and message. The animation won't prevent you from using the console as normal. Here's an example:
317
318 ```python
319 from time import sleep
320 from rich.console import Console
321
322 console = Console()
323 tasks = [f"task {n}" for n in range(1, 11)]
324
325 with console.status("[bold green]Working on tasks...") as status:
326 while tasks:
327 task = tasks.pop(0)
328 sleep(1)
329 console.log(f"{task} complete")
330 ```
331
332 This generates the following output in the terminal.
333
334 ![status](https://github.com/textualize/rich/raw/master/imgs/status.gif)
335
336 The spinner animations were borrowed from [cli-spinners](https://www.npmjs.com/package/cli-spinners). You can select a spinner by specifying the `spinner` parameter. Run the following command to see the available values:
337
338 ```
339 python -m rich.spinner
340 ```
341
342 The above command generates the following output in the terminal:
343
344 ![spinners](https://github.com/textualize/rich/raw/master/imgs/spinners.gif)
345
346 </details>
347
348 <details>
349 <summary>Tree</summary>
350
351 Rich can render a [tree](https://rich.readthedocs.io/en/latest/tree.html) with guide lines. A tree is ideal for displaying a file structure, or any other hierarchical data.
352
353 The labels of the tree can be simple text or anything else Rich can render. Run the following for a demonstration:
354
355 ```
356 python -m rich.tree
357 ```
358
359 This generates the following output:
360
361 ![markdown](https://github.com/textualize/rich/raw/master/imgs/tree.png)
362
363 See the [tree.py](https://github.com/textualize/rich/blob/master/examples/tree.py) example for a script that displays a tree view of any directory, similar to the linux `tree` command.
364
365 </details>
366
367 <details>
368 <summary>Columns</summary>
369
370 Rich can render content in neat [columns](https://rich.readthedocs.io/en/latest/columns.html) with equal or optimal width. Here's a very basic clone of the (MacOS / Linux) `ls` command which displays a directory listing in columns:
371
372 ```python
373 import os
374 import sys
375
376 from rich import print
377 from rich.columns import Columns
378
379 directory = os.listdir(sys.argv[1])
380 print(Columns(directory))
381 ```
382
383 The following screenshot is the output from the [columns example](https://github.com/textualize/rich/blob/master/examples/columns.py) which displays data pulled from an API in columns:
384
385 ![columns](https://github.com/textualize/rich/raw/master/imgs/columns.png)
386
387 </details>
388
389 <details>
390 <summary>Markdown</summary>
391
392 Rich can render [markdown](https://rich.readthedocs.io/en/latest/markdown.html) and does a reasonable job of translating the formatting to the terminal.
393
394 To render markdown import the `Markdown` class and construct it with a string containing markdown code. Then print it to the console. Here's an example:
395
396 ```python
397 from rich.console import Console
398 from rich.markdown import Markdown
399
400 console = Console()
401 with open("README.md") as readme:
402 markdown = Markdown(readme.read())
403 console.print(markdown)
404 ```
405
406 This will produce output something like the following:
407
408 ![markdown](https://github.com/textualize/rich/raw/master/imgs/markdown.png)
409
410 </details>
411
412 <details>
413 <summary>Syntax Highlighting</summary>
414
415 Rich uses the [pygments](https://pygments.org/) library to implement [syntax highlighting](https://rich.readthedocs.io/en/latest/syntax.html). Usage is similar to rendering markdown; construct a `Syntax` object and print it to the console. Here's an example:
416
417 ```python
418 from rich.console import Console
419 from rich.syntax import Syntax
420
421 my_code = '''
422 def iter_first_last(values: Iterable[T]) -> Iterable[Tuple[bool, bool, T]]:
423 """Iterate and generate a tuple with a flag for first and last value."""
424 iter_values = iter(values)
425 try:
426 previous_value = next(iter_values)
427 except StopIteration:
428 return
429 first = True
430 for value in iter_values:
431 yield first, False, previous_value
432 first = False
433 previous_value = value
434 yield first, True, previous_value
435 '''
436 syntax = Syntax(my_code, "python", theme="monokai", line_numbers=True)
437 console = Console()
438 console.print(syntax)
439 ```
440
441 This will produce the following output:
442
443 ![syntax](https://github.com/textualize/rich/raw/master/imgs/syntax.png)
444
445 </details>
446
447 <details>
448 <summary>Tracebacks</summary>
449
450 Rich can render [beautiful tracebacks](https://rich.readthedocs.io/en/latest/traceback.html) which are easier to read and show more code than standard Python tracebacks. You can set Rich as the default traceback handler so all uncaught exceptions will be rendered by Rich.
451
452 Here's what it looks like on OSX (similar on Linux):
453
454 ![traceback](https://github.com/textualize/rich/raw/master/imgs/traceback.png)
455
456 </details>
457
458 All Rich renderables make use of the [Console Protocol](https://rich.readthedocs.io/en/latest/protocol.html), which you can also use to implement your own Rich content.
459
460 # Rich CLI
461
462
463 See also [Rich CLI](https://github.com/textualize/rich-cli) for a command line application powered by Rich. Syntax highlight code, render markdown, display CSVs in tables, and more, directly from the command prompt.
464
465
466 ![Rich CLI](https://raw.githubusercontent.com/Textualize/rich-cli/main/imgs/rich-cli-splash.jpg)
467
468 # Textual
469
470 See also Rich's sister project, [Textual](https://github.com/Textualize/textual), which you can use to build sophisticated User Interfaces in the terminal.
471
472 ![Textual screenshot](https://raw.githubusercontent.com/Textualize/textual/main/imgs/textual.png)
473