Skip to main content

Terminal executor for AI agents, with ANSI escape sequence support and image screenshots

Project description

Terminal Executor

Terminal executor for AI agents, with ANSI escape sequence support and image screenshots.

License: UNLICENSE PyPI PyPI Downloads Code style: black

Demo

Using termexec for solving the "vimgolf-test" challenge:

vimgolf-test-success

More info at vimgolf-gym

Installation

# install from pypi
pip install termexec

# or install the latest version from github
pip install git+https://github.com/james4ever0/termexec.git

Note: if your platform does not have prebuilt binaries of agg-python-bindings, just install cargo and rustc so the source code could compile.

Usage

from termexec import TerminalExecutor
import time

# Initializes executor with a command to run in terminal emulator, using avt as backend, with automatic context cleanup
with TerminalExecutor(['bash'], width=80, height=24) as executor:
    # Waits for the terminal emulator to be ready.
    time.sleep(1)  # Adjust sleep time as necessary for your environment

    # Or if you prefer to wait for terminal idle event
    try:
        executor.terminal.wait_for_terminal_idle(duration=1, timeout=10)
    except TimeoutError:
        print("Terminal did not become idle in time.")

    # Get the current display of the terminal emulator as a string.
    terminal_text = executor.display
    print("Terminal Display:")
    print(terminal_text)

    # Send input to the terminal emulator.
    executor.input("echo Hello, World!\n")
    print("After input:")
    print(executor.display)

    # Saves the current display of the terminal emulator as a .png file
    executor.screenshot("screenshot.png")
    print("Screenshot saved as screenshot.png")

    # Get the PID of the terminal process.
    print("Terminal process PID:", executor.terminal.pty_process.pid)

Alternatives

  • Xterm.js running in phantomjs, electron or headless playwright

  • LXterminal running in kiosk mode with x11vnc and novnc

License

The Unlicense

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

termexec-0.0.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

termexec-0.0.3-py2.py3-none-any.whl (7.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file termexec-0.0.3.tar.gz.

File metadata

  • Download URL: termexec-0.0.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.19

File hashes

Hashes for termexec-0.0.3.tar.gz
Algorithm Hash digest
SHA256 55d24eaa0278e8c9fa0b000174e54eb12ea3369d5d0520999de6d85e37ad56d1
MD5 9732ad7004eeca6c0dd3772e755369f9
BLAKE2b-256 2b1a2234b23ca0079a17bf8d54bb1cbaf697e2816cbce99f54628c8bf8d8045d

See more details on using hashes here.

File details

Details for the file termexec-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: termexec-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.19

File hashes

Hashes for termexec-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d54ed5ce42b2beafbf1b406c0c2b019713baf1fa87cdf25c8e756ccbdd2679d8
MD5 6a46f6f6399c92d0e0a891422ebab3ee
BLAKE2b-256 6d755234a4964b37a08c7feb02c6ec63e71b288b83d4d8459d2fe252ec7f7f4d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page