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(b"sudo apt-get upgrade\n")
        await asyncio.sleep(1)
        print((await term.read_new_output()).decode())

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

        print(result.output.decode())
        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-2.0.2.tar.gz (7.2 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-2.0.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for virtual_term-2.0.2.tar.gz
Algorithm Hash digest
SHA256 f41ef6df0d3d5fba6cfcae40db20c0b634d187556fb8a95f1a35df1b235da66d
MD5 cb901483a604e2b060e67d0271d6db96
BLAKE2b-256 9a7058a09b0fac9361405e29eb3bfd0e2e70d817b0c8524f9bbfd3506d1b8ce1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: virtual_term-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.0 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-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e35bf87b6c11372107815ee1027caac875fba876272214bfd079728e63e04a42
MD5 2bd7c82abe3c5040df3ad326d0ebe901
BLAKE2b-256 0de6cf3b90ac1e600f81e99c0f7085d122810c1a133dd6eb4217ab18b9b9d4ac

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