{"id":10137,"library":"pyte","title":"Pyte Terminal Emulator","description":"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.","status":"active","version":"0.8.2","language":"en","source_language":"en","source_url":"https://github.com/selectel/pyte","tags":["terminal","emulator","vt100","ansi","cli"],"install":[{"cmd":"pip install pyte","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Screen","correct":"from pyte import Screen"},{"symbol":"Stream","correct":"from pyte import Stream"}],"quickstart":{"code":"import pyte\nimport sys\n\n# Create a screen and a stream\nscreen = pyte.Screen(columns=80, rows=24)\nstream = pyte.Stream(screen)\n\n# Feed some data, must be bytes\nstream.feed(b\"\\x1b[31mHello, \\x1b[32mWorld!\\x1b[0m\\r\\n\")\nstream.feed(b\"\\x1b[1mThis is bold.\\x1b[0m\\r\\n\")\nstream.feed(b\"\\x1b[3mThis is italic.\\x1b[0m\\r\\n\")\n\n# Print the current state of the screen\nfor row_str in screen.display:\n    sys.stdout.write(row_str)\n\nprint(f\"\\nCursor position: ({screen.cursor.x}, {screen.cursor.y})\")\nprint(f\"Current mode: {screen.mode}\")","lang":"python","description":"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."},"warnings":[{"fix":"Update `Screen` instantiation: `Screen(columns=80, rows=24)` instead of `Screen(cols=80, rows=24)`.","message":"The constructor for `pyte.Screen` changed its parameter names in version 0.6.0. The `cols` parameter was renamed to `columns`.","severity":"breaking","affected_versions":">=0.6.0"},{"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'))`.","message":"The `pyte.Stream.feed()` method strictly requires a `bytes`-like object. Passing a plain string (str) will result in a `TypeError`.","severity":"gotcha","affected_versions":"all"},{"fix":"Validate input sequences if possible, or be prepared to handle non-standard behavior by resetting the screen or carefully processing known sequence subsets.","message":"Pyte 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Encode the string to bytes before feeding, e.g., `stream.feed('text'.encode())` or use a bytes literal `stream.feed(b'text')`.","cause":"Attempting to feed a string directly to `pyte.Stream.feed()` instead of a bytes object.","error":"TypeError: a bytes-like object is required, not 'str'"},{"fix":"Change `cols` to `columns` in the `Screen` constructor, e.g., `pyte.Screen(columns=80, rows=24)`.","cause":"Using the old `cols` parameter name for the `pyte.Screen` constructor after version 0.6.0.","error":"TypeError: Screen.__init__() got an unexpected keyword argument 'cols'"},{"fix":"Access cursor attributes via the `cursor` object: `screen.cursor.x`, `screen.cursor.y`.","cause":"Accessing cursor position attributes (e.g., `cursor_x`, `cursor_y`) directly on the `Screen` object. The cursor is an object accessible via `screen.cursor`.","error":"AttributeError: 'pyte.Screen' object has no attribute 'cursor_x'"}]}