프로그래밍/Python
[python] Rich is a Python library for rich text and beautiful formatting in the terminal.
홍반장水_
2024. 12. 11. 18:18
반응형
https://pypi.org/project/rich/
Rich is a Python library for rich text and beautiful formatting in the terminal.
The Rich API 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.
python -m pip install rich
from rich.progress import Progress
import time
def main():
with Progress() as progress:
task1 = progress.add_task("[cyan]Downloading...", total=100)
task2 = progress.add_task("[magenta]Processing...", total=200)
while not progress.finished:
time.sleep(0.03) # Simulate some work
progress.update(task1, advance=1)
progress.update(task2, advance=0.5)
if __name__ == "__main__":
main()
from rich.progress import Progress
import time
def main():
# Create a progress bar
with Progress() as progress:
# Add a task
task = progress.add_task("[cyan]Processing...", total=100)
# Update progress
for i in range(100):
time.sleep(0.05) # Simulate some work
progress.update(task, advance=1) # Advance the progress bar by 1
if __name__ == "__main__":
main()
반응형