Skip to main content

A simple Python library for creating and interacting with virtual terminals

Project description

VirtualTerm

A simple Python library for creating and interacting with virtual terminals

VirtualTerm is a Python library designed for creating and managing virtual terminal sessions programmatically. It allows users to run interactive shell commands, handle command timeouts, and monitor output streams within isolated terminal environments. This library is particularly useful for developers building automation tools, testing environments, or managing interactive shell-based workflows.

import asyncio
from virtual_term import VirtualTerm

async def main():
    with await VirtualTerm.spawn() as term:
        term.write("sudo apt-get upgrade\n")
        await asyncio.sleep(1)
        print(term.read_new_output().decode())

        term.write("y\n")  # Respond with 'y' to confirm upgrade
        result = await term.wait_for_last_command()

        print(result.output)
        assert result.return_code == 0

asyncio.run(main())

Installation

Install with pip:

pip install virtual-term

Development

VirtualTerm uses Rye for dependency management and development workflows. To get started with development, ensure you have Rye installed, then clone the repository and set up the environment:

git clone https://github.com/MatthewScholefield/virtual-term.git
cd virtual-term
rye sync
rye run pre-commit install

# Run tests
rye test

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

virtual_term-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

virtual_term-1.0.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file virtual_term-1.0.0.tar.gz.

File metadata

  • Download URL: virtual_term-1.0.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for virtual_term-1.0.0.tar.gz
Algorithm Hash digest
SHA256 80e0fbea2d30b3b1280edb5ba2aee7db5bb76ecf8295f463c7a509beacb7982f
MD5 a8c8a9463ea8a075792b9f09a941b72d
BLAKE2b-256 99ba3ae4a465cd76355d574a10bdc8b0116d55510e4dc5919b0c6b0e22a66e75

See more details on using hashes here.

File details

Details for the file virtual_term-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: virtual_term-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for virtual_term-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31a6781aa2a2c6d7cd36029165011c0e13eb5863b51454bb9fde51b025550380
MD5 3158b6154113b0b56dfd8a795c2dc134
BLAKE2b-256 1e10e3196c45d24838fff7520d78098e4fe2dbf07773b121f5e56b006c54321b

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