Volver al ranking

bczsalba/pytermgui

Pythonptg.bczsalba.com

Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!

python3pythontypingtuiterminalansi-escape-sequencesansi-escape-codesguipytermguicross-platformansicli
Crecimiento de estrellas
Estrellas
2.7k
Forks
62
Crecimiento semanal
Issues
9
1k2k
abr 2021ene 2023oct 2024jul 2026
ArtefactosPyPIpip install pytermgui
README

title

Python TUI framework with mouse support, modular widget system, customizable and rapid terminal markup language and more!

pip3 install pytermgui

PyPi project Code quality

Notice

A much better, more complete version of PTG's core ideas now exists over at Shade 40. While PTG is not yet fully obsolete, those libraries will be the primary focus of development going forward.


Why?

Mostly because terminals are cool, but creating terminal apps has historically been difficult. PyTermGUI aims to provide a simple, readable and modular way to make the app of your dreams!

Terminal apps are (often):

  • Easier to install
  • Faster & more resource efficient
  • Less prone to differences between environments (no IE7 here!)

...than their web or native counterparts.

How?

We provide a couple of things to make your life easier:

  • Sensible abstractions over most terminal standards
  • A fully fledged, desktop-inspired window manager system with modals and completely customizable windows
  • Mouse support out of the box with 0 configuration
  • YAML (or Python) based styling engines
  • TIM, our markup language for creating styled terminal text with expressive text, including systems for aliases & macros
  • A bunch of things I can't think of right now :slightly_smiling_face:

Additionally, there are a couple of neat tools to make your general Python development easier:

  • An inspection utility
  • A pretty printer for both the REPL and IPython
  • A way to create SVG and HTML screenshots of your terminal

Examples

All images below are generated directly from the source displayed by a PyTermGUI-powered SVG exporter tool, Termage.

Your first application, a simple clock:

import time

import pytermgui as ptg

def macro_time(fmt: str) -> str:
    return time.strftime(fmt)

ptg.tim.define("!time", macro_time)

with ptg.WindowManager() as manager:
    manager.layout.add_slot("Body")
    manager.add(
        ptg.Window("[bold]The current time is:[/]\n\n[!time 75]%c", box="EMPTY")
    )

Since strings are converted into the Label widget, and all widgets use markup for styling, we can use a custom-defined TIM macro function to return the current time. After running the above, you should see something like:

Clock example output

For something a bit more in-depth, see this contact form inspired by asciimatics' example:

import pytermgui as ptg

CONFIG = """
config:
    InputField:
        styles:
            prompt: dim italic
            cursor: '@72'
    Label:
        styles:
            value: dim bold

    Window:
        styles:
            border: '60'
            corner: '60'

    Container:
        styles:
            border: '96'
            corner: '96'
"""

with ptg.YamlLoader() as loader:
    loader.load(CONFIG)

with ptg.WindowManager() as manager:
    window = (
        ptg.Window(
            "",
            ptg.InputField("Balazs", prompt="Name: "),
            ptg.InputField("Some street", prompt="Address: "),
            ptg.InputField("+11 0 123 456", prompt="Phone number: "),
            "",
            ptg.Container(
                "Additional notes:",
                ptg.InputField(
                    "A whole bunch of\nMeaningful notes\nand stuff", multiline=True
                ),
                box="EMPTY_VERTICAL",
            ),
            "",
            ["Submit", lambda *_: submit(manager, window)],
            width=60,
            box="DOUBLE",
        )
        .set_title("[210 bold]New contact")
        .center()
    )

    manager.add(window)

This showcases the YAML-based config system, as well as some additional API. I recommended checking out the source file to see how the submit callback works.

Contact form example output

Not a fan of colors? We've got you!

PyTermGUI is one of the only TUI libraries that offers NO_COLOR support that doesn't suck ruin the usability & design of your apps.

This is how the above example looks like with the environment variable NO_COLOR set to anything. Note how contrast between colors is retained, as well as the inclusion of background colors:

Contact form NO_COLOR output

Older terminals? No problem!

We use algorithms based on human vision to convert and downgrade colors when the current terminal emulator doesn't support them. Here is a cool screenshot:

Contact form NO_COLOR output

Disclaimer: Termage currently doesn't play nicely to changing colorsystems during runtime, so this image had to be captured natively :(

Questions? See the docs!

Pretty much every single name in the library, private or public, has an insightful dockstring attached to it, and we are accumulating a growing amount of walkthrough-based documentations articles. See 'em all on the doc website!

Contributions, issues et al.

If you have any problems using the library, feel free to open up a discussion or raise an issue ticket. If you would prefer to hack on the library yourself, see the contribution guidelines. Pull requests are encouraged, but make sure you aren't trying to fix an issue that others are already working on, for your own sake. :slightly_smiling_face:

Repositorios relacionados
fastapi/fastapi

FastAPI framework, high performance, easy to learn, fast to code, ready for production

PythonPyPIMIT Licensepythonjson
fastapi.tiangolo.com
100.8k9.7k
sherlock-project/sherlock

Hunt down social media accounts by username across social networks

PythonPyPIMIT Licenseosintreconnaissance
sherlockproject.xyz
86.9k10.2k
666ghj/MiroFish

A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物

PythonPyPIGNU Affero General Public License v3.0agent-memoryfinancial-forecasting
mirofish.ai
69.1k10.8k
Asabeneh/30-Days-Of-Python

The 30 Days of Python programming challenge is a step-by-step guide to learn the Python programming language in 30 days. This challenge may take more than 100 days. Follow your own pace. These videos may help too: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw

PythonPyPI30-days-of-pythonpython
68.8k12.8k
Textualize/rich

Rich is a Python library for rich text and beautiful formatting in the terminal.

PythonPyPIMIT Licensepythonpython3
rich.readthedocs.io/en/latest/
56.9k2.3k
astral-sh/ruff

An extremely fast Python linter and code formatter, written in Rust.

Rustcrates.ioMIT Licenselinterpep8
docs.astral.sh/ruff
48.8k2.3k
666ghj/BettaFish

微舆:人人可用的多Agent舆情分析助手,打破信息茧房,还原舆情原貌,预测未来走向,辅助决策!从0实现,不依赖任何框架。

PythonPyPIGNU General Public License v2.0agent-frameworkdata-analysis
deepwiki.com/666ghj/BettaFish
41.8k7.6k
mouredev/Hello-Python

Curso para aprender el lenguaje de programación Python desde cero y para principiantes. 100 clases, 44 horas en vídeo, código, proyectos y grupo de chat. Fundamentos, frontend, backend, testing, IA...

PythonPyPIApache License 2.0fastapimongodb
mouredev.link/python
36.5k2.3k
doocs/leetcode

🔥LeetCode solutions in any programming language | 多种编程语言实现 LeetCode、《剑指 Offer(第 2 版)》、《程序员面试金典(第 6 版)》题解

JavaMavenCreative Commons Attribution Share Alike 4.0 Internationalalgorithmscpp
leetcode.doocs.org
36.3k9.4k
soxoj/maigret

🕵️‍♂️ Collect a dossier on a person by username from 3000+ sites

PythonPyPIMIT Licenseosintsocial-network
maigret.app
35.6k2.7k
zhayujie/chatgpt-on-wechat

基于大模型搭建的聊天机器人,同时支持 微信公众号、企业微信应用、飞书、钉钉 等接入,可选择GPT3.5/GPT-4o/GPT-o1/ DeepSeek/Claude/文心一言/讯飞星火/通义千问/ Gemini/GLM-4/Claude/Kimi/LinkAI,能处理文本、语音和图片,访问操作系统和互联网,支持基于自有知识库进行定制企业智能客服。

PythonPyPIMIT Licensechatgptwechat
docs.link-ai.tech/cow
35.5k9k
celery/celery

Distributed Task Queue (development branch)

PythonPyPIOtherpythontask-manager
docs.celeryq.dev
28.7k5.1k