Convert Figma logo to code with AI

Textualize logotextual

The lean application framework for Python. Build sophisticated user interfaces with a simple Python API. Run your apps in the terminal and a web browser.

26,124
811
26,124
186

Top Related Projects

27,461

A powerful little TUI framework 🏗

49,200

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

2,831

Console user interface library for Python (official repo)

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations

Library for building powerful interactive command line applications in Python

Quick Overview

Textual is a Python framework for creating sophisticated Text User Interfaces (TUIs) and terminal applications. It provides a rich set of widgets and tools to build interactive, responsive, and visually appealing console-based applications with minimal effort.

Pros

  • Easy to use with a high-level API, allowing rapid development of complex TUIs
  • Cross-platform compatibility, working on Windows, macOS, and Linux
  • Rich set of pre-built widgets and layouts for creating diverse interfaces
  • Supports modern terminal features like true color and emojis

Cons

  • Limited to terminal environments, not suitable for GUI applications
  • Learning curve for developers new to TUI paradigms
  • May have performance limitations for extremely complex interfaces
  • Dependency on third-party libraries for some advanced features

Code Examples

  1. Creating a simple "Hello, World!" app:
from textual.app import App, ComposeResult
from textual.widgets import Static

class HelloWorld(App):
    def compose(self) -> ComposeResult:
        yield Static("Hello, World!")

if __name__ == "__main__":
    app = HelloWorld()
    app.run()
  1. Adding a button with an event handler:
from textual.app import App, ComposeResult
from textual.widgets import Button

class ButtonApp(App):
    def compose(self) -> ComposeResult:
        yield Button("Click me!", id="my_button")

    def on_button_pressed(self, event: Button.Pressed) -> None:
        if event.button.id == "my_button":
            self.exit(message="Button clicked!")

if __name__ == "__main__":
    app = ButtonApp()
    app.run()
  1. Creating a simple form with input fields:
from textual.app import App, ComposeResult
from textual.widgets import Input, Button

class FormApp(App):
    def compose(self) -> ComposeResult:
        yield Input(placeholder="Enter your name")
        yield Input(placeholder="Enter your email", id="email")
        yield Button("Submit", id="submit")

    def on_button_pressed(self, event: Button.Pressed) -> None:
        if event.button.id == "submit":
            email = self.query_one("#email", Input).value
            self.exit(message=f"Form submitted with email: {email}")

if __name__ == "__main__":
    app = FormApp()
    app.run()

Getting Started

To get started with Textual, follow these steps:

  1. Install Textual using pip:

    pip install textual
    
  2. Create a new Python file (e.g., my_app.py) and import the necessary modules:

    from textual.app import App, ComposeResult
    from textual.widgets import Static
    
  3. Define your app class and compose method:

    class MyApp(App):
        def compose(self) -> ComposeResult:
            yield Static("Welcome to my Textual app!")
    
    if __name__ == "__main__":
        app = MyApp()
        app.run()
    
  4. Run your app:

    python my_app.py
    

This will create a simple Textual app with a static text widget. You can build upon this foundation to create more complex and interactive TUIs.

Competitor Comparisons

27,461

A powerful little TUI framework 🏗

Pros of Bubbletea

  • Written in Go, offering better performance and easier deployment
  • Simpler API with a focus on composability and functional programming
  • Lightweight and minimal dependencies

Cons of Bubbletea

  • Less feature-rich compared to Textual's extensive widget library
  • Limited styling options and layout control
  • Steeper learning curve for developers not familiar with Go

Code Comparison

Bubbletea (Go):

func (m model) View() string {
    return fmt.Sprintf("Hello, %s!", m.name)
}

Textual (Python):

class HelloWorld(App):
    def compose(self) -> ComposeResult:
        yield Label(f"Hello, {self.name}!")

Both frameworks provide a declarative approach to building TUIs, but Textual offers a more Pythonic syntax and richer set of built-in widgets. Bubbletea's simplicity and performance make it attractive for Go developers, while Textual's extensive features and Python ecosystem integration appeal to those familiar with Python.

Bubbletea excels in scenarios requiring high performance and minimal resource usage, whereas Textual shines in complex applications with rich user interfaces and rapid prototyping needs.

49,200

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

Pros of Rich

  • Simpler to use for basic text formatting and styling
  • Lighter weight and faster for simple console output
  • More focused on console output rather than full TUI applications

Cons of Rich

  • Less suitable for creating complex, interactive TUI applications
  • Limited layout and widget capabilities compared to Textual
  • Lacks built-in support for user input and event handling

Code Comparison

Rich:

from rich import print

print("[bold red]Hello[/bold red] [green]World[/green]!")

Textual:

from textual.app import App, ComposeResult
from textual.widgets import Label

class HelloWorld(App):
    def compose(self) -> ComposeResult:
        yield Label("Hello World!")

HelloWorld().run()

Rich is more straightforward for simple console output, while Textual provides a framework for building complete TUI applications with widgets and layouts. Rich focuses on enhancing console output, whereas Textual offers a full-fledged TUI development environment with more advanced features and interactivity.

2,831

Console user interface library for Python (official repo)

Pros of urwid

  • Mature and stable library with a long history of development
  • Lightweight and efficient, suitable for resource-constrained environments
  • Extensive widget set and customization options

Cons of urwid

  • Steeper learning curve due to lower-level API
  • Less modern and intuitive syntax compared to newer libraries
  • Limited documentation and community resources

Code Comparison

urwid:

import urwid

def exit_on_q(key):
    if key in ('q', 'Q'):
        raise urwid.ExitMainLoop()

main = urwid.Padding(urwid.Text(u"Hello World"), left=2, right=2)
top = urwid.Overlay(main, urwid.SolidFill(u'\N{MEDIUM SHADE}'),
    align='center', width=('relative', 60),
    valign='middle', height=('relative', 60),
    min_width=20, min_height=9)
urwid.MainLoop(top, unhandled_input=exit_on_q).run()

Textual:

from textual.app import App, ComposeResult
from textual.widgets import Header, Footer

class HelloWorld(App):
    def compose(self) -> ComposeResult:
        yield Header()
        yield Footer()

    def on_mount(self) -> None:
        self.sub_title = "Hello World!"

if __name__ == "__main__":
    app = HelloWorld()
    app.run()

The code comparison shows that Textual offers a more modern, declarative approach to building TUIs, while urwid requires a more imperative style. Textual's syntax is generally more concise and easier to read for newcomers to TUI development.

A cross platform package to do curses-like operations, plus higher level APIs and widgets to create text UIs and ASCII art animations

Pros of asciimatics

  • More mature and stable project with a longer history
  • Supports a wider range of terminal types and platforms
  • Includes built-in animation and special effects capabilities

Cons of asciimatics

  • Less active development and community support
  • More complex API, potentially steeper learning curve
  • Limited modern UI components compared to Textual

Code Comparison

asciimatics:

from asciimatics.screen import Screen
from asciimatics.scene import Scene
from asciimatics.effects import Cycle, Stars
from asciimatics.renderers import FigletText

def demo(screen):
    effects = [
        Cycle(
            screen,
            FigletText("ASCIIMATICS", font='big'),
            int(screen.height / 2 - 8)),
        Stars(screen, 200)
    ]
    screen.play([Scene(effects, 500)])

Screen.wrapper(demo)

Textual:

from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Button

class MyApp(App):
    def compose(self) -> ComposeResult:
        yield Header()
        yield Button("Click me!")
        yield Footer()

if __name__ == "__main__":
    app = MyApp()
    app.run()

Library for building powerful interactive command line applications in Python

Pros of python-prompt-toolkit

  • Focused on building interactive command-line applications
  • Extensive features for command-line interfaces (auto-completion, syntax highlighting, etc.)
  • Lightweight and can be easily integrated into existing projects

Cons of python-prompt-toolkit

  • Limited to terminal-based interfaces
  • Less suitable for creating full-screen applications or complex layouts
  • Steeper learning curve for advanced features

Code Comparison

python-prompt-toolkit:

from prompt_toolkit import prompt

user_input = prompt('Enter your name: ')
print(f"Hello, {user_input}!")

Textual:

from textual.app import App
from textual.widgets import Input

class NameApp(App):
    def compose(self):
        yield Input(placeholder="Enter your name")

NameApp().run()

Summary

python-prompt-toolkit excels in creating interactive command-line interfaces with advanced features like auto-completion and syntax highlighting. It's lightweight and easily integrable but limited to terminal-based applications. Textual, on the other hand, is designed for building full-screen TUI applications with complex layouts and widgets, offering a more comprehensive framework for text-based user interfaces. The code comparison illustrates the difference in approach, with python-prompt-toolkit focusing on simple prompts and Textual providing a more structured, widget-based system for user input.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Discord Supported Python Versions PyPI version OS support

textual-splash

Textual

clock

Build cross-platform user interfaces with a simple Python API. Run your apps in the terminal or a web browser.

Textual's API combines modern Python with the best of developments from the web world, for a lean app development experience. De-coupled components and an advanced testing framework ensure you can maintain your app for the long-term.

Want some more examples? See the examples directory.

"""
An App to show the current time.
"""

from datetime import datetime

from textual.app import App, ComposeResult
from textual.widgets import Digits


class ClockApp(App):
    CSS = """
    Screen { align: center middle; }
    Digits { width: auto; }
    """

    def compose(self) -> ComposeResult:
        yield Digits("")

    def on_ready(self) -> None:
        self.update_clock()
        self.set_interval(1, self.update_clock)

    def update_clock(self) -> None:
        clock = datetime.now().time()
        self.query_one(Digits).update(f"{clock:%T}")


if __name__ == "__main__":
    app = ClockApp()
    app.run()

[!TIP] Textual is an asynchronous framework under the hood. Which means you can integrate your apps with async libraries — if you want to. If you don't want or need to use async, Textual won't force it on you.

Widgets

Textual's library of widgets covers everything from buttons, tree controls, data tables, inputs, text areas, and more… Combined with a flexible layout system, you can realize any User Interface you need.

Predefined themes ensure your apps will look good out of the box.

buttons

tree

datatables

inputs

listview

textarea

Installing

Install Textual via pip:

pip install textual textual-dev

See getting started for details.

Demo

Run the following command to see a little of what Textual can do:

python -m textual

Or try the textual demo without installing (requires uv):

uvx --python 3.12 textual-demo

Dev Console

devtools

How do you debug an app in the terminal that is also running in the terminal?

The textual-dev package supplies a dev console that connects to your application from another terminal. In addition to system messages and events, your logged messages and print statements will appear in the dev console.

See the guide for other helpful tools provided by the textual-dev package.

Command Palette

Textual apps have a fuzzy search command palette. Hit ctrl+p to open the command palette.

It is easy to extend the command palette with custom commands for your application.

Command Palette

Textual ❤️ Web

textual-serve

Textual apps are equally at home in the browser as they are the terminal. Any Textual app may be served with textual serve — so you can share your creations on the web. Here's how to serve the demo app:

textual serve "python -m textual"

In addition to serving your apps locally, you can serve apps with Textual Web.

Textual Web's firewall-busting technology can serve an unlimited number of applications.

Since Textual apps have low system requirements, you can install them anywhere Python also runs. Turning any device in to a connected device. No desktop required!

Join us on Discord

Join the Textual developers and community on our Discord Server.