Registry / serialization / pyte
library0.8.2pypypi✓ verified 87d ago

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.

pip install pyte
INSTALL
IMPORT
SIG · PYTE
P
pyte
serializationpythonv0.8.2
Install
1.7s avg
Import
80ms
Disk
21MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.084s · 25MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.7s · import 0.076s · 25MB
21MB installed
● package 21MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Screen
from pyte import Screen
Stream
from pyte import Stream

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}")
Debug
Known issues
breakingThe constructor for `pyte.Screen` changed its parameter names in version 0.6.0. The `cols` parameter was renamed to `columns`.
fix
Update `Screen` instantiation: `Screen(columns=80, rows=24)` instead of `Screen(cols=80, rows=24)`.
affects: >=0.6.0
gotchaThe `pyte.Stream.feed()` method strictly requires a `bytes`-like object. Passing a plain string (str) will result in a `TypeError`.
fix
Ensure all input to `feed()` is encoded to bytes, for example, `stream.feed(b'some text')` or `stream.feed('some text'.encode('utf-8'))`.
affects: all
gotchaPyte aims for VTXXX compatibility. Feeding non-standard or malformed ANSI escape sequences might lead to an inconsistent or unexpected screen state without raising an explicit error, making debugging difficult.
fix
Validate input sequences if possible, or be prepared to handle non-standard behavior by resetting the screen or carefully processing known sequence subsets.
affects: all
Errors
Common errors & fixes
TypeError: a bytes-like object is required, not 'str'
Attempting to feed a string directly to `pyte.Stream.feed()` instead of a bytes object.
fix
Encode the string to bytes before feeding, e.g., `stream.feed('text'.encode())` or use a bytes literal `stream.feed(b'text')`.
TypeError: Screen.__init__() got an unexpected keyword argument 'cols'
Using the old `cols` parameter name for the `pyte.Screen` constructor after version 0.6.0.
fix
Change `cols` to `columns` in the `Screen` constructor, e.g., `pyte.Screen(columns=80, rows=24)`.
AttributeError: 'pyte.Screen' object has no attribute 'cursor_x'
Accessing cursor position attributes (e.g., `cursor_x`, `cursor_y`) directly on the `Screen` object. The cursor is an object accessible via `screen.cursor`.
fix
Access cursor attributes via the `cursor` object: `screen.cursor.x`, `screen.cursor.y`.
Upgrade
Version history
0.8.2latest on PyPI · released Nov 12, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
pyte — pip install pyte · libregistry