Skip to main content

libghostty-py

This is a fork of pyghostty (from this commit).

Python bindings for libghostty-vt, Ghostty's embeddable terminal emulation core, a headless, high-fidelity VT emulator. These bindings cover terminal state, screen and scrollback snapshots, kitty graphics, and everything else Ghostty's production terminal core handles.

The binding is Python-ABI-independent: pure Python (cffi ABI mode) over a bundled libghostty-vt shared library, so one wheel per platform covers every Python version. No compiler is needed at install time. Wheel builds cover Linux and macOS (x86-64 and ARM64) and Windows (x86-64).

Usage

from ghostty import Terminal

with Terminal(cols=80, rows=24) as t:
    t.feed('hello\r\nworld')
    t.cursor      # (x, y), 0-indexed
    t.text()      # plain text of the visible screen only
    t.contents()  # everything: scrollback plus screen, soft-wraps unwrapped
    t.resize(120, 24)  # reflows the primary screen

The base layer, ghostty._cdef/_ffi, exposes the complete generated C API as raw ffi/lib (regenerate with gen_cdef.py after updating the pinned libghostty-vt release).

ghostty.core.Terminal provides an ergonomic wrapper for commonly used parts.

Restoring a terminal on reconnect

serialize() returns VT bytes, rather than plain text or Ghostty's binary snapshot format. Feed the result to a terminal with the same columns, rows, and character-width rules, then forward subsequent PTY bytes in order:

with Terminal(cols=80, rows=24) as t:
    t.feed(b"hello\r\n\x1b[31mprompt> ")
    initial_output = t.serialize()
    # Send initial_output to the reconnecting terminal before live PTY output.

The snapshot resets the destination and restores screen content, scrollback, styles, cursor, modes, and the active alternate screen with its underlying primary screen. Use serialize(palette=True) to also export the palette.

Snapshots may end with incomplete UTF-8 or VT sequences: send bytes directly, or use a streaming decoder across the snapshot and live output. Serialize between feeds/resizes and send the snapshot before subsequent output. Unfinished input is limited by continuation_limit (1 MiB by default); exceeding it raises GhosttyError until the sequence completes.

Graphics, titles, default colors, inactive alternate screens, and arbitrary saved cursors are not exported. Rendering can differ between terminal emulators.

Building the library

The shared library is built from a Ghostty checkout with Zig 0.17.0. Install that Zig version on PATH, or download the pinned official toolchain with python install_zig.py (downloads are verified against recorded SHA-256 hashes):

GHOSTTY_SRC=/path/to/ghostty python build_lib.py

Without GHOSTTY_SRC, the build looks for a checkout in ghostty-src/ inside this project.

The checkout must be at a locally available stable release tag in the same major series as vt-version in pyproject.toml, at or above that version (currently vt-1.0.2 or any later stable 1.x release). Release CI builds the exact configured version. This runs zig build -Demit-lib-vt=true and copies the resulting shared library into ghostty/_lib/, where the package loader and wheel builds pick it up.

Using an external shared library

Wheel builds bundle libghostty-vt by default. To build a Python-only wheel without compiling or bundling Ghostty, pass --config-settings=bundle=false:

python -m pip install . --config-settings=bundle=false

The resulting wheel is platform-independent and does not need Zig to build. This also excludes any library left by an earlier bundled build. The loader checks the bundled library, then the active Python environment (sys.prefix):

  • Linux: lib/libghostty-vt.so
  • macOS: lib/libghostty-vt.dylib
  • Windows: Library/bin/ghostty-vt.dll

Libraries installed in these locations are found automatically. The external library must provide the ABI of libghostty-vt 1.0.0, which upstream guarantees for all stable 1.x releases.

Bundled builds require Zig 0.17.0 on PATH or the local toolchain installed by python install_zig.py. Release CI installs the verified toolchain before building. The bundle setting accepts true or false and defaults to true.

Development

pip install -e .[dev]
python install_zig.py
GHOSTTY_SRC=/path/to/ghostty python build_lib.py
pytest -q

To test against headless xterm.js:

npm install --prefix /tmp/libghostty-xterm @xterm/headless@6.0.0
LIBGHOSTTY_XTERM_MODULE=/tmp/libghostty-xterm/node_modules/@xterm/headless pytest -q

Versioning

Set the package version in pyproject.toml. Python exposes it as ghostty.__version__.

Releases

Pushing a v* tag runs .github/workflows/release.yml, which builds and tests one Python-ABI-independent wheel for each supported platform and publishes the wheels to GitHub and PyPI. Releases are wheel-only; source remains available from the corresponding GitHub tag.

Metadata

Release files for libghostty-py 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for libghostty-py 0.3.2
File Actions
libghostty_py-0.3.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for libghostty_py-0.3.2-py3-none-win_amd64.whl
libghostty_py-0.3.2-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for libghostty_py-0.3.2-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
libghostty_py-0.3.2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64, Linux glibc 2.27+ ARM64 Details for libghostty_py-0.3.2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
libghostty_py-0.3.2-py3-none-macosx_13_0_x86_64.whl Python 3 none macOS 13.0+ x86-64 Details for libghostty_py-0.3.2-py3-none-macosx_13_0_x86_64.whl
libghostty_py-0.3.2-py3-none-macosx_13_0_arm64.whl Python 3 none macOS 13.0+ ARM64 Details for libghostty_py-0.3.2-py3-none-macosx_13_0_arm64.whl

Total release size: 9.5 MB

Release files / libghostty_py-0.3.2-py3-none-win_amd64.whl

Download URL libghostty_py-0.3.2-py3-none-win_amd64.whl
Size 1.1 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
b2e7f69650d2995d8c206c506eed26a9dae2a408b9b617dd0a1dcada6a0c2605
BLAKE2b-256 checksum
How to use checksums
05cb2c466fc7dc7063d37ff28602c0962dad6db48c43d168e839a11014f86a8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / libghostty_py-0.3.2-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL libghostty_py-0.3.2-py3-none-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
23b60c4a017edbc1af031a085184d71000fa94539d84b982a25e6c5fa9322467
BLAKE2b-256 checksum
How to use checksums
1e7c05c08fb58ad8ea1678abdad6f3b3f82ddcfd3b75b5d6c729522b1763b64b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / libghostty_py-0.3.2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

Download URL libghostty_py-0.3.2-py3-none-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl
Size 3.2 MB
Tags Linux glibc 2.27+ ARM64 Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
0aaf29517c6e8447f5bb76c0b6a6e9a6740deb6dda37880279cea67a13d0f76b
BLAKE2b-256 checksum
How to use checksums
268c5fb13408964f18e392fb8cbfd04f54836647e2c7badaa199914c3d59435b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / libghostty_py-0.3.2-py3-none-macosx_13_0_x86_64.whl

Download URL libghostty_py-0.3.2-py3-none-macosx_13_0_x86_64.whl
Size 915.8 kB
Tags Python 3 macOS 13.0+ x86-64
SHA-256 checksum
How to use checksums
51e2777b277cf6dfa58a6c6b5671c475836d73332b5a0bae3078af8a5d37464e
BLAKE2b-256 checksum
How to use checksums
58fdfb32925ed577fe3c0a53f6b4535fa80b7a6af48a1cf6bad85eba7e63d73a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Release files / libghostty_py-0.3.2-py3-none-macosx_13_0_arm64.whl

Download URL libghostty_py-0.3.2-py3-none-macosx_13_0_arm64.whl
Size 852.5 kB
Tags Python 3 macOS 13.0+ ARM64
SHA-256 checksum
How to use checksums
66a062207b5a27044adc914f9f3769870104524cdb8636b86bd1adafdf17a723
BLAKE2b-256 checksum
How to use checksums
ab9db71e31ef5cddab131b9f3fb70ea76edca9f435d2823eb8fcfb4a81c130ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

Security for libghostty-py 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for libghostty_py-0.3.2-py3-none-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page