libvt is a pure-Python, zero-dependency, typed virtual terminal emulator
and streaming VT parser (Parser → Terminal / Screen / Snapshot +
Events). It ships a transport-only asyncio stream and POSIX PTY
adapter (libvt.aio), a namespace-safe pytest plugin
(libvt.pytest_plugin), mode-aware input encoders (libvt.input), and
visual boxed screen assertions (libvt.testing), serving
libtmux and general Python
terminal testing without LGPL copyleft obligations.
Follow the conventions already in the tree, and keep a change scoped to what was asked for.
| Path | What it is |
|---|---|
src/libvt/parser.py, modes.py, style.py, config.py, profiles.py |
VT500 byte parser, CSI subparameters, modes, SGR styles, Profile / Policy / Limits, and host presets |
src/libvt/_ucd.py, _grid.py, screen.py, terminal.py |
Unicode 17 width/clustering tables, packed viewport & RLE scrollback rows, Screen / ScreenSet, Terminal, Snapshot, and Formatter |
src/libvt/status.py, events.py, input.py, codec.py |
Rex OSC 7501 program status store, open Event hierarchy, mode-aware input encoders, and cold-path VT sequence explainer |
src/libvt/graphics.py, contrib/tmux/ |
Zero-dependency SIXEL / Kitty APC G placement tracker and decoupled tmux profile / capture / window / control modules |
src/libvt/aio.py, __main__.py, exc.py |
AsyncTerminalStream, POSIX open_pty(), python -m libvt CLI (explain, render, strip), and exceptions |
src/libvt/testing.py |
Zero-dependency assert_screen, assert_screen_box, FlightRecorder diagnostics, and boxed VT + SGR vt_screen / serialize_vt_snapshot / format_vt_diff_lines utilities |
src/libvt/pytest_plugin.py |
Import-light pytest11 plugin (libvt[pytest]): vt_terminal, vt_factory, vt_recorder, vt_parser, and vt_pty |
src/libvt/contrib/syrupy.py |
Optional syrupy .ambr adapter (libvt[syrupy]): VtSnapshotExtension and conditional vt_snapshot pytest11 hook |
tests/ |
Functional, property-fuzz, PTY, CLI, and fixture tests organized by module under test |
docs/ |
Sphinx/MyST site: topics/ (concepts), api/ (autodoc), project/ (contributing, releasing, ADRs 0001–0010) |
scripts/ |
Unicode table generator (generate_ucd.py) and VT throughput benchmarks (bench_vt.py, benchmark.py) |
README.md |
Doctested quickstart — every >>> block is a real test |
CHANGES |
The changelog, rendered as a docs page |
MIGRATION |
Deprecation and migration notes |
conftest.py |
Root fixtures, including doctest_namespace seeding |
- Documentation, user-facing text,
CHANGES, release notes, commit messages, docstrings, and source comments: .github/WRITING.md - Environment, the gates, tests, documentation builds, releases, and pull requests: .github/CONTRIBUTING.md
Each of those is the single home for its subject. Where a rule seems to be stated twice, the file listed above is the one that governs.
- Make the smallest coherent change that solves the verified problem; keep unrelated cleanup out of it.
- Reuse an existing file, helper, API, or test before adding a new one.
- Add a file only for a durable boundary — a distinct responsibility, independent reuse, or splitting an oversized module — not for a single-use helper or a one-line re-export.
- Keep new APIs private until a caller outside the module needs them.
- Add a test for every user-visible behaviour change, and a
CHANGESentry for every change to the public API, configuration, or output. - A passing gate is evidence only once it has been shown capable of failing. Pair a new test with a deliberate break that proves it bites.
- Maintain strict clean-room MIT provenance: derive state transitions
and test vectors from public standards (ECMA-48, ITU T.416, Unicode
UAX #11 / #29, Paul Flo Williams' VT500 state diagram) and permissive
(
MIT,ISC,Apache-2.0,BSD) references — never copy or translate fromLGPLorGPLterminal implementations (pyte,vte/GTK,asciinema).
Python >= 3.12 is the compatibility floor, and runtime dependencies stay
empty (dependencies = []). Importing libvt performs no I/O and does
not load asyncio, pty, or pytest.
Give callers the most precise signature that covers supported behavior. Use
object for a parameter only when every value is valid or when the function
accepts unknown input for validation. Narrow unknown values before using them.
Reserve Any for an inherently dynamic interface where Python cannot express
the input contract. Explain the reason there and keep unchecked values out of
the rest of the API.
Before weakening a type, inspect real callers and try a precise alternative. A union can describe known alternatives, a protocol can name the operations a caller must provide, and a type parameter can preserve the relationship between an input and its result. Try both a supported call and a plausible misuse with ty. Check what downstream callers infer, whether the error is understandable, and whether existing valid calls still work. Never widen a type, cast a value, or suppress a diagnostic solely to make the checker pass.
- Repository: https://github.com/tmux-python/libvt
- Documentation: https://libvt.git-pull.com/
- libtmux: https://libtmux.git-pull.com/
- DEC ANSI Parser state machine: https://vt100.net/emu/dec_ansi_parser