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.1.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.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: virtual_term-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0aa49b9893b46b4d89bccbc25630afc208303321d2bc7bfc7bae369670e274b6
MD5 3a90630bfc7a9ac19d52044c54089895
BLAKE2b-256 6aa0c527f778fae8f266521ba8ff20875cb3b8c2406a668e5c72f95abd25730f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: virtual_term-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 806808e736b604d17f2b8b666e3f1aa09e75721e038f32098f0c6adba705bf6a
MD5 a8146f2853bc758db36d12165af166f3
BLAKE2b-256 8b27f934df006eff59cf9af7ff7fef922dea71ac936a96bcde8bbe6dd062d394

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