Textual Serve

1.1.3 · active · verified Mon Apr 13

textual-serve is an open-source project that allows you to serve and access your Textual TUI (Text-based User Interface) applications via a web browser. The Textual app runs on a machine/server under your control and communicates with the browser via a custom protocol over WebSockets. End-users interacting with the app via their browser do not have direct access to the machine the application is running on, only to the running Textual app. It effectively turns Textual TUIs into multi-user web applications. The current version is 1.1.3, and it has a regular release cadence with recent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple Textual application and then serve it using `textual-serve`. The `Server` class takes a shell command to launch your Textual app. The app will be accessible in a web browser, typically at `http://localhost:8000` by default.

from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Static
from textual_serve.server import Server

class MinimalApp(App):
    BINDINGS = [("q", "quit", "Quit")]
    def compose(self) -> ComposeResult:
        yield Header()
        yield Static("Hello from Textual Served!")
        yield Footer()

    def action_quit(self) -> None:
        self.exit()

# Save the above Textual app as 'my_app.py'
# Then run the textual-serve server programmatically:
# Note: This will block and serve the app on http://localhost:8000
# You can also use the command line: textual serve my_app.py

if __name__ == "__main__":
    # To run a Textual app directly:
    # app = MinimalApp()
    # app.run()

    # To serve it via textual-serve
    print("Starting textual-serve on http://localhost:8000...")
    print("Press Ctrl+C to stop the server.")
    server = Server("python my_app.py", host="localhost", port=8000)
    server.serve()

view raw JSON →