create account

Python - Console Improvements - Rich Library by agileautomation

View this thread on: hive.blogpeakd.comecency.com
· @agileautomation ·
$0.29
Python - Console Improvements - Rich Library
https://snipboard.io/icvPrl.jpg

All python developers will be using the console to print out messages or debug info at times in their development and some of these consoles can be running continuously, with many messages.

Being able to format and color highlight these is a NICE way to improve our scripts and to highlight specific messages which is easily done with the "Rich" library.

**Rich** allows you to use rich text formatting in the terminal and its super easy to use!
```
pip install rich
```

You can simply import the print function from the rich library and print will now be color syntax highlighting automatically for you with all its other features.  It still uses the same inputs as the built in print, so its compatible with anything you already have written.

```
from rich import print
```
### Color Syntax Highlighting
If you then print an object or data element, rich colors things nicely for you.

![image.png](https://files.peakd.com/file/peakd-hive/agileautomation/23t76y5JTvs6tABdbEZHND7zRBgrQ5u9oKM3ppD7nLveSjxFha47rDRrmpRe1QfokeCwv.png)

![image.png](https://files.peakd.com/file/peakd-hive/agileautomation/23t793AB3gZRCv7izkQ2Q1pdeoA3UwH5n44whMLNFWCy2nM7roksiPJCJnrVn7bUukgsJ.png)


### Justification
```
from rich.console import Console

console = Console(width=20)

style = "bold white on blue"
console.print("Rich", style=style)
console.print("Rich", style=style, justify="left")
console.print("Rich", style=style, justify="center")
console.print("Rich", style=style, justify="right")
This produces the following output:

Rich
Rich                
        Rich        
                Rich
```

### Creating progress bars
```
from rich.progress import track
 
for num in track(range(100)):
    print(num * 2)
    time.sleep(0.1)
```

More Examples:

![image.png](https://files.peakd.com/file/peakd-hive/agileautomation/23sweNjTPhGbzoUHAWTUunhLG82Kt32AAuJf5ywERrHD9wbMRy2RJdWKhd1zy7Dqp3syy.png)

### Table Formatting
This is a really powerful feature and hard to do with terminal output directly, so this is an impressive feature of rich.
```
from rich.table import Table
from rich.console import Console
 
table = Table("First table using rich!")
table.add_column("Language", justify="right", style="bright_yellow", no_wrap=True)
table.add_column("Year Initially Released", style="green")
table.add_column("Most recent version", justify="right", style="red")
 
table.add_row("", "Python", "1991", "3.9.1")
table.add_row("", "R", "1993", "4.0.3")
table.add_row("", "Java", "1995", "Java 15")
 
console = Console()
console.print(table)
```


![image.png](https://files.peakd.com/file/peakd-hive/agileautomation/23t6vTKug2ZBPLmtsjAE8ziR4sEiMXdqmG8uZgtKaAti84dZWm3hys2gAjmR9krdfBHbL.png)

What have you used Rich to do with your scripts?

I hope you found some useful tips here and that you go try out rich with your python applications!
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authoragileautomation
permlinkpython-console-improvements-rich-library
categoryhive-129924
json_metadata{"app":"peakd/2023.11.3","format":"markdown","tags":["python","learning","programming","development"],"users":[],"image":["https://snipboard.io/icvPrl.jpg","https://files.peakd.com/file/peakd-hive/agileautomation/23t76y5JTvs6tABdbEZHND7zRBgrQ5u9oKM3ppD7nLveSjxFha47rDRrmpRe1QfokeCwv.png","https://files.peakd.com/file/peakd-hive/agileautomation/23t793AB3gZRCv7izkQ2Q1pdeoA3UwH5n44whMLNFWCy2nM7roksiPJCJnrVn7bUukgsJ.png","https://files.peakd.com/file/peakd-hive/agileautomation/23sweNjTPhGbzoUHAWTUunhLG82Kt32AAuJf5ywERrHD9wbMRy2RJdWKhd1zy7Dqp3syy.png","https://files.peakd.com/file/peakd-hive/agileautomation/23t6vTKug2ZBPLmtsjAE8ziR4sEiMXdqmG8uZgtKaAti84dZWm3hys2gAjmR9krdfBHbL.png"]}
created2024-01-16 15:40:00
last_update2024-01-16 15:40:00
depth0
children6
last_payout2024-01-23 15:40:00
cashout_time1969-12-31 23:59:59
total_payout_value0.144 HBD
curator_payout_value0.144 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,869
author_reputation55,848,601,723
root_title"Python - Console Improvements - Rich Library"
beneficiaries
0.
accountdbuzz
weight200
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,528,724
net_rshares687,010,458,090
author_curate_reward""
vote details (29)
@ganjafarmer ·
Oh. I don't understand anything that you have said... 

Absolutely and 100% completely Klingon..

However this is interesting and I absolutely need as much help as I can possibly get in surviving learning about python. 

Hopefully I can trade you my secrets of Hive class and how to earn more here on the blockchain.

Left alone the fact that you can work and code here on the blockchain and make good money as well... Oh I've got friends that have needs all the time. 

Sweet! 

Vote for you! Right on I'm excited to invest in you. 
👍  
properties (23)
authorganjafarmer
permlinkre-agileautomation-2024117t233819629z
categoryhive-129924
json_metadata{"type":"comment","tags":["hive-129924","python","learning","programming","development"],"app":"ecency/3.0.44-mobile","format":"markdown+html"}
created2024-01-18 07:38:21
last_update2024-01-18 07:38:21
depth1
children4
last_payout2024-01-25 07:38:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length533
author_reputation672,900,775,922,025
root_title"Python - Console Improvements - Rich Library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,573,092
net_rshares94,974,877
author_curate_reward""
vote details (1)
@agileautomation ·
$0.02
Thanks mate, I appreciate that and yes, I'd love to combine more crypto/blockchain with my programming skills!
👍  
properties (23)
authoragileautomation
permlinkre-ganjafarmer-s7g8de
categoryhive-129924
json_metadata{"tags":["hive-129924"],"app":"peakd/2023.11.3"}
created2024-01-18 08:46:27
last_update2024-01-18 08:46:27
depth2
children3
last_payout2024-01-25 08:46:27
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.011 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length110
author_reputation55,848,601,723
root_title"Python - Console Improvements - Rich Library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,574,013
net_rshares59,124,582,193
author_curate_reward""
vote details (1)
@ganjafarmer ·
Come find me in the free compliments discord. Would that work?
👍  
properties (23)
authorganjafarmer
permlinkre-agileautomation-2024118t0495667z
categoryhive-129924
json_metadata{"type":"comment","tags":["hive-129924"],"app":"ecency/3.0.44-mobile","format":"markdown+html"}
created2024-01-18 08:49:06
last_update2024-01-18 08:49:06
depth3
children2
last_payout2024-01-25 08:49:06
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length62
author_reputation672,900,775,922,025
root_title"Python - Console Improvements - Rich Library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,574,064
net_rshares121,806,494
author_curate_reward""
vote details (1)
@hivebuzz ·
Congratulations @agileautomation! You have completed the following achievement on the Hive blockchain And have been rewarded with New badge(s)

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@agileautomation/posts.png?202401161911"></td><td>You published more than 10 posts.<br>Your next target is to reach 20 posts.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@agileautomation) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


**Check out our last posts:**
<table><tr><td><a href="/hive-122221/@hivebuzz/lpud-202401"><img src="https://images.hive.blog/64x128/https://i.imgur.com/pVZi2Md.png"></a></td><td><a href="/hive-122221/@hivebuzz/lpud-202401">LEO Power Up Day - January 15, 2024</a></td></tr></table>
👍  
properties (23)
authorhivebuzz
permlinknotify-agileautomation-20240116t192925
categoryhive-129924
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2024-01-16 19:29:24
last_update2024-01-16 19:29:24
depth1
children0
last_payout2024-01-23 19:29:24
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length970
author_reputation370,792,828,599,978
root_title"Python - Console Improvements - Rich Library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id130,533,881
net_rshares122,932,118
author_curate_reward""
vote details (1)