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.1.tar.gz (7.1 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.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: virtual_term-2.0.1.tar.gz
  • Upload date:
  • Size: 7.1 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.1.tar.gz
Algorithm Hash digest
SHA256 1d218c4deaf9bc06705b9e04e1c44e24b7be0106cdafbd0f5c8520f44f4b8730
MD5 15bfd2524e6a9311f9c5f6e96c776e56
BLAKE2b-256 30a109c49f848d449560e558e19969e0a40ba4cb7a0c17006281b24774f58f21

See more details on using hashes here.

File details

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

File metadata

  • Download URL: virtual_term-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9e8db3af4649b896023224ab7834d010aa3e080141b51893b529dc1b34a4cfc7
MD5 e1d09a3c2e00437f62770c37147a46c3
BLAKE2b-256 6895c69965e67f6bd1ddbeadadbe9e8211843148aa6b92fbe939f0f8083130ae

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