This example demonstrates how to create a web-based terminal using FastHTML and XTermJS.
This application creates a browser-based terminal that connects to a real shell on the server. It uses:
- FastHTML for the web application framework
- XTermJS for the terminal interface
- WebSockets for bidirectional communication
- PTY (pseudo-terminal) for shell interaction
-
Install the requirements:
pip install -r requirements.txt -
Run the application:
python main.py -
Open your browser and navigate to:
http://localhost:5001
The implementation consists of two main files:
main.py: The server-side Python application that creates the PTY and handles WebSocket communicationstatic/terminal.js: The client-side JavaScript that initializes XTermJS and manages the WebSocket connection
To learn more about FastHTML, check out the FastHTML documentation.