Pyte Terminal Emulator

0.8.2 · active · verified Fri Apr 17

Pyte is a simple, VTXXX-compatible terminal emulator library for Python. It processes ANSI escape sequences and maintains the state of a terminal screen, allowing programmatic interaction with terminal output without a GUI. The current version is 0.8.2, and it has a moderate release cadence, with updates typically for bug fixes and minor features.

Common errors

Warnings

Install

Imports

Quickstart

Initializes a `pyte.Screen` and `pyte.Stream`, feeds some basic ANSI-encoded text, and then prints the current state of the screen to standard output, including cursor position and mode.

import pyte
import sys

# Create a screen and a stream
screen = pyte.Screen(columns=80, rows=24)
stream = pyte.Stream(screen)

# Feed some data, must be bytes
stream.feed(b"\x1b[31mHello, \x1b[32mWorld!\x1b[0m\r\n")
stream.feed(b"\x1b[1mThis is bold.\x1b[0m\r\n")
stream.feed(b"\x1b[3mThis is italic.\x1b[0m\r\n")

# Print the current state of the screen
for row_str in screen.display:
    sys.stdout.write(row_str)

print(f"\nCursor position: ({screen.cursor.x}, {screen.cursor.y})")
print(f"Current mode: {screen.mode}")

view raw JSON →