Rich is a Python library for rich textual jabber and supreme formatting within the terminal.
The Rich API makes it easy to add shade and magnificence to terminal output. Rich can even render somewhat tables, growth bars, markdown, syntax highlighted provide code, tracebacks, and additional — out of the sector.
For a video introduction to Rich take a look at calmcode.io by @fishnets88.
Compatibility
Rich works with Linux, OSX, and Dwelling windows. Perfect shade / emoji works with unique Dwelling windows Terminal, traditional terminal is specific to 8 colors.
Rich also works with Jupyter notebooks with out a extra configuration required.
Inserting in
Set up with pip
or your popular PyPi package manager.
pip set up rich
Rich print characteristic
To without distress add rich output to your utility, you can import the rich print technique, which has the the same signature because the builtin Python characteristic. Achieve that:
from rich import print print("Hi there, [bold magenta]World[/bold magenta]!", ":vampire:", locals())
The usage of the Console
For added protect watch over over rich terminal jabber, import and invent a Console object.
from rich.console import Console console = Console()
The Console object has a print
technique which has an intentionally equivalent interface to the builtin print
characteristic. Right here’s an example of exercise:
console.print("Hi there", "World!")
As you’ll depend on, this would print "Hi there World!"
to the terminal. Demonstrate that unlike the builtin print
characteristic, Rich will note-wrap your textual jabber to compare within the terminal width.
There are about a systems of including shade and magnificence to your output. You presumably can situation a style for the total output by including a style
keyword argument. Right here’s an example:
console.print("Hi there", "World!", style="courageous purple")
The output would possibly be one thing bask in the following:
That is good-hunting for styling a line of textual jabber at a time. For added finely grained styling, Rich renders a diversified markup which is equivalent in syntax to bbcode. Right here’s an example:
console.print("The set there is a [bold cyan]Will[/bold cyan] there [u]is[/u] a [i]come[/i].")
Console logging
The Console object has a log()
technique which has a equivalent interface to print()
, nonetheless also renders a column for the unique time and the file and line which made the resolution. By default Rich will raise out syntax highlighting for Python structures and for repr strings. If you log a series (i.e. a dict or a listing) Rich will somewhat print it in declare that it suits within the on hand dwelling. Right here’s an example of nearly all these aspects.
from rich.console import Console console = Console() test_data = [ {"jsonrpc": "2.0", "method": "sum", "params": [None, 1, 2, 4, False, True], "identification": "1",}, {"jsonrpc": "2.0", "technique": "notify_hello", "params": [7]}, {"jsonrpc": "2.0", "technique": "subtract", "params": [42, 23], "identification": "2"}, ] def test_log(): enabled = Fraudulent context = { "foo": "bar", } movies = ["Deadpool", "Rise of the Skywalker"] console.log("Hi there from", console, "!") console.log(test_data, log_locals=Perfect) test_log()
The above produces the following output:
Demonstrate the log_locals
argument, which outputs a table containing the local variables the set the log technique became as soon as called.
The log technique would possibly maybe also very successfully be old for logging to the terminal for lengthy operating functions corresponding to servers, nonetheless is also a extremely good debugging help.
Logging Handler
You presumably can even exercise the builtin Handler class to format and colorize output from Python’s logging module. Right here’s an example of the output:
Emoji
To insert an emoji in to console output space the title between two colons. Right here’s an example:
>>> console.print(":smiley: :vampire: :pile_of_poo: :thumbs_up: :raccoon:") 😃 🧛 💩 👍 🦝
Please exercise this selection wisely.
Tables
Rich can render flexible tables with unicode field characters. There is a unheard of diversity of formatting recommendations for borders, kinds, cell alignment and tons others.
The animation above became as soon as generated with table_movie.py within the examples directory.
Right here’s a less advanced table example:
from rich.console import Console from rich.table import Column, Desk console = Console() table = Desk(show_header=Perfect, header_style="courageous magenta") table.add_column("Date", style="unlit", width=12) table.add_column("Title") table.add_column("Manufacturing Value range", account for="appropriate") table.add_column("Field Administrative heart", account for="appropriate") table.add_row( "Dev 20, 2019", "Superstar Wars: The Upward push of Skywalker", "$275,000,000", "$375,126,118" ) table.add_row( "Would per chance maybe well 25, 2018", "[red]Solo[/red]: A Superstar Wars Chronicle", "$275,000,000", "$393,151,347", ) table.add_row( "Dec 15, 2017", "Superstar Wars Ep. VIII: The Final Jedi", "$262,000,000", "[bold]$1,332,539,889[/bold]", ) console.print(table)
This produces the following output:
Demonstrate that console markup is rendered within the the same became as soon as as print()
and log()
. In actuality, the rest that is renderable by Rich would possibly maybe be integrated within the headers / rows (even other tables).
The Desk
class is orderly ample to resize columns to compare the on hand width of the terminal, wrapping textual jabber as required. Right here’s the the same example, with the terminal made smaller than the table above:
Progress Bars
Rich can render a pair of flicker-free growth bars to music lengthy-operating tasks.
For overall usage, wrap any sequence within the music
characteristic and iterate over the outcome. Right here’s an example:
from rich.growth import music for step in music(vary(100)): do_step(step)
It be no longer necessary harder to add a pair of growth bars. Right here’s an example taken from the docs:
The columns would possibly maybe be configured to reveal any crucial points you will want. Constructed-in columns encompass share total, file size, file trail, and time last. Right here’s one other example showing a download in growth:
To strive this out yourself, take a look at examples/downloader.py which will download a pair of URLs concurrently whereas showing growth.
Columns
Rich can render jabber in neat columns with equal or optimum width. Right here’s a extremely overall clone of the (MacOS / Linux) ls
reveal which displays a directory itemizing in columns:
import os from rich import print from rich.columns import Columns directory = os.listdir(sys.argv[1]) print(Columns(directory))
The following screenshot is the output from the columns example which displays data pulled from an API in columns:
Markdown
Rich can render markdown and does an reasonable job of translating the formatting to the terminal.
To render markdown import the Markdown
class and invent it with a string containing markdown code. Then print it to the console. Right here’s an example:
from rich.console import Console from rich.markdown import Markdown console = Console() with commence("README.md") as readme: markdown = Markdown(readme.be taught()) console.print(markdown)
This would possibly occasionally invent output one thing bask in the following:
Syntax Highlighting
Rich uses the pygments library to enforce syntax highlighting. Utilization is akin to rendering markdown; invent a Syntax
object and print it to the console. Right here’s an example:
from rich.console import Console from rich.syntax import Syntax my_code = ''' def iter_first_last(values: Iterable[T]) -> Iterable[Tuple[bool, bool, T]]: """Iterate and generate a tuple with a flag for first and final tag.""" iter_values = iter(values) strive: previous_value = subsequent(iter_values) in addition to StopIteration: return first = Perfect for tag in iter_values: yield first, Fraudulent, previous_value first = Fraudulent previous_value = tag yield first, Perfect, previous_value ''' syntax = Syntax(my_code, "python", theme="monokai", line_numbers=Perfect) console = Console() console.print(syntax)
This would possibly occasionally invent the following output:
Tracebacks
Rich can render supreme tracebacks which would possibly maybe be easier to be taught and reveal extra code than customary Python tracebacks. You presumably can situation Rich because the default traceback handler so all uncaught exceptions would possibly be rendered by Rich.
Right here’s what it looks bask in on OSX (equivalent on Linux):
Right here’s what it looks bask in on Dwelling windows:
Peek the rich traceback documentation for the runt print.
viagra for your brain viagra tб»± nhiГЄn tб»« trГЎi cГўy cho cбєЈ hai giб»›i generic viagra manufacturers india
homework persuasive essay research paper essay writing a thank you speech
brand viagra canadian pharmacies chinese viagra pills viagra no prescription
expository essay help research paper charts student research paper
mba admission essay help where can i pay someone to write my essay creative college application essays
new ed treatments https://sildenafilxxl.com/ buy generic viagra online
criminal law dissertation apa format for essay writing homework help geometry
research paper quizlet essay on my college life help with essays
argumentative where to buy research papers esl writing narrative essay
mastercard that accept viagra top of the line where to get viagra viagra sample pack
essay spacing between paragraphs writing literary essays science homework help ks3
essay on self help is the best help essay for college application 11th grade essay writing
erectile dysfunction pills canadian pharmacy online erectile dysfunction cure
cialis 20mg cheap cialis generic cialis bitcoin
natural cures for ed canadian drug stores viagra without doctor prescription amazon
prescription without a doctor’s prescription Amoxil levitra without a doctor prescription
buy generic ed pills online canadian online pharmacy online drugstore
erectyle dysfunction generic drugs over the counter ed medication
medicines for ed cheap generic drugs from india new erectile dysfunction treatment
where to bay cialis (tadalafil) pills 80mg cialis coupon cialis lowest price
cheapest ed pills generic drugs herbal ed
medications online: pharmacy medications cat antibiotics without pet prescription
medications online: the best ed pill best online canadian pharmacy
cialis from bc, no prescription cialis price comparison no prescription cialis for sale payment paypal
zithromax cost zithromax without prescription where can i get zithromax
price of cialis at walmart cheap cialis professional 800 mg black cialis over night ship 800 mg
viagra otc best over the counter viagra viagra discount
viagra otc viagra 100mg viagra generic
viagra amazon viagra pills where can i buy viagra
zithromax 600 mg tablets can you buy zithromax online zithromax z-pak
where can i purchase zithromax online how to get zithromax online can you buy zithromax over the counter in mexico
viagra testosterone pfizer viagra online pay for viagra by paypal
cialis no prescription 30 day free trial cialis cialis black 800
viagra online viagra 100mg over the counter viagra
viagra plus dapoxetine alternative viagra viagra australia
need to get samples of viagra without a perscription buy viagra oneline buy viagra with dapoxetine
how to get viagra generic viagra 100mg viagra 100mg
viagra from canada
is viagra over the counter generic viagra 100mg order viagra online
generic name for viagra
buy viagra online cheap generic viagra canada where to buy viagra online
viagra prescription online
cheap cialis by post cialis original online cialis soft
pfizer viagra without prescription viagra for cheap buy viagra without rx
viagra 4 packs viagra online stores generic viagra from india
walmart viagra prescriptions buy viagra online without prescription viagra generic 100mg
buy prescription drugs online legally erectile dysfunction pills ed meds
ed meds Aciclovir buy Aciclovir
can ed be cured men’s ed pills buy erectile dysfunction pills online
erection pills online buy erectile dysfunction medications online cheap erectile dysfunction pills online
prices of viagra at walmart canadian pharmacy online pharmacies without an rx
Читать далее: гидра сайт
ed natural remedies Aciclovir Zovirax
ed treatment options cause of ed prescription drugs online without
best ed solution lipitor generic india lipitor generic
viagra over the counter generic viagra india viagra pill
buying ed pills online how to overcome ed naturally ed online pharmacy
pet antibiotics without vet prescription buy lipitor online lipitor generic india
buy drug online where to buy lipitor cheap lipitor generic
mens ed pills canada online pharmacy canada drugs
cvs viagra https://cheapvgr100.com/ snjtgsib
Taxi moto line
128 Rue la Boétie
75008 Paris
+33 6 51 612 712
Taxi moto paris
I like it when individuals come together and share opinions.
Great site, continue the good work!
foppuiyq cheap viagra how much does viagra cost
break 20mg cialis half
viagra 75mg
cialis cost increase Cag wef
cheap valtrex canada where can you buy acyclovir cream buy zovirax cream australia
yasmin prescription australia yasmin 0 03 mg 3 mg buying clomid online
76 mg benadryl zyrtec-d insomnia benadryl cream uk
can i buy acyclovir cream over the counter buy acyclovir can i buy valtrex over the counter
zyrtec 10 mg pill 900 mg benadryl allegra 40 tablets
allegra prescription 5mg benadryl tablets where can i buy zyrtec d
amoxicillin 500 mg brand name antibiotic what is antibiotic resistance
canada cialis http://cialisirt.online/ buy viagra cialis aanhcgzj
buy viagra online cheap http://viagrastm.com/ goodrx viagra jgvaftck
discount viagra http://viagrastm.online/ buying viagra online nnnjxucr
where to get viagra http://viagrastm.com/ price of viagra ktqhcyly
where to buy viagra online http://viagrastm.online/ canadian viagra kqkdfwsy
real cialis without a doctor’s prescription canadian express pharmacy doctors for erectile dysfunction
purchasing viagra online in canada
buy cialis lowest price
viagra seus genericos Cag wef
ed products viagra generic drugs herbal remedies for ed
canadian generic viagra pharmacy
viagra tablets price in pakistan
buy cialis viagra levitra Cag wef
buy viagra in pattaya
buying viagra in germany
buy dapoxetine in usa Cag wef
buy cialis online australia
viagra 75mg
5mg cialis daily use Cag wef
pharma pharmacies near me best drugstore foundation for dry skin
drug store near me http://pharmacy-onlineasxs.com/ rx
cheap viagra online canadian pharmacy treatment for erectile dysfunction texas state board of pharmacy
online pharmacy without scripts discount pharmacy card п»їviagra online canadian pharmacy
med rx pharmacy best canadian pharmacy erectile dysfunction causes
muse for ed https://canadarx24.com/
pet meds without vet prescription canada
best online pharmacy best ed pills canadian pharmacies
home remedies for erectile dysfunction https://canadarx24.com/
vitality ed pills
peoples pharmacy on line pharmacy canada rx pharmacy
viagra sales from canadian pharmacy
pfizer viagra 100mg
cialis to buy in south africa Cag wef
viagra canada https://edcheapgeneric.com/ puqrlkpd online viagra
purchase viagra at boots chemist
buy viagra online cheap
how much viagra cost with prescription Cag wef
cvs prescription prices without insurance http://canadarx24.online/ pumps for ed bznsuisj
erectile dysfunction medications http://canadarx24.online/ errection problem cure zguxgxnx
herbal replacement for viagra/cialis/levitra… vwzbxqct http://edcheapgeneric.online/ cialis without a doctor’s prescription
viagra without prescription https://edcheapgeneric.com/ lppvijhn viagra without a doctor prescription usa
taking l-citrulline and cialis together fcejkkcp http://edcheapgeneric.online/ cialis pills
the best ed drug http://canadarx24.online/ male dysfunction pills mwdxpecp
ghkv viagra amazon http://dietkannur.org utxb cymb
otvf viagra discount http://dietkannur.org tvms fhhy
hvvi viagra online http://dietkannur.org goja nhab
kfbu viagra over the counter http://dietkannur.org nybf gokr
moob viagra online canadian pharmacy http://dietkannur.org kgxd qisy
nhlb viagra coupons http://dietkannur.org ivur nahz
european cialis cialis & dapoxitine cialis shipping [url=http://cialijomen.com/]buy cialis online[/url] ’
what\’s the difference in viagra generic viagra 100 4 pack viagra on line [url=http://acialaarx.com/]where to buy viagra in tucson without prescription in person[/url] ’
canadian meds cialis cialis at costco cialis and paypal [url=http://mycialedst.com/]cialis 20mg price[/url] ’
does cialis make you bigger zcxfipoi http://tadedmedz.com/ cialis pills for sale
nizoral order online
tadalafil 10mg prices uk
order tadalafil ups Cag wef
viagra and cialis discount cialis no prescription uk cialis where to buy [url=http://phrcialiled.com/]cialis dose[/url] ’
paypal cialis tadalafil best price for cialis cialis online [url=http://21cialismen.com/]price of cialis[/url] ’
cialis vs viagra effectiveness yhyekgfi http://tadedmedz.online/ real cialis online with paypal
viagra online overnight shipping viagra overnight no prescription cialis and viagra mix [url=http://llviabest.com/]viagra professional australia[/url] ’
viagra prices walgreens professional viagra online viagra 100mg professional [url=http://genqpviag.com/]super force viagra[/url] ’
how much is viagra in tuajuana with a prescription generic viagra next day best generic viagra [url=http://genericrxxx.com/]viagra canada[/url] ’
viagra without doctor script viagra only 0.2$
prescription viagra without a doctor viagra Without a Doctor Prescription
viagra natural para hombres generic viagra viagra on without insurance [url=http://xz-pharmacyonline.com/en/career-opportunities.html]generic viagra[/url] ’
generic cialis 20mg generic cialis price of cialis [url=http://cialmenshoprx.com/]prolonged effects of cialis[/url] ’
cialis price canada Female Cialis Soft cialis professional wikipedia [url=https://xz-pharmacyonline.com]panacea pharmacy[/url] ’
viagraorcialis which is better viagra cialis or levitra cialis black australia [url=http://loncialis.com/]voucher cialis index[/url] ’
viagra and celexa viagra lowest priced professional brand viagra info [url=https://canadianpharmacy-usx.com/organic.htm]buy viagra australia online[/url] ’
http://zithromaxfast500.com zithromax cost