Skip to main content

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

Metadata

Release files for virtual-term 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for virtual-term 2.0.2
File Size Uploaded
virtual_term-2.0.2.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for virtual-term 2.0.2
File Interpreter ABI Platform
virtual_term-2.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / virtual_term-2.0.2.tar.gz

Download URL virtual_term-2.0.2.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f41ef6df0d3d5fba6cfcae40db20c0b634d187556fb8a95f1a35df1b235da66d
BLAKE2b-256 checksum
How to use checksums
9a7058a09b0fac9361405e29eb3bfd0e2e70d817b0c8524f9bbfd3506d1b8ce1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release files / virtual_term-2.0.2-py3-none-any.whl

Download URL virtual_term-2.0.2-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e35bf87b6c11372107815ee1027caac875fba876272214bfd079728e63e04a42
BLAKE2b-256 checksum
How to use checksums
0de6cf3b90ac1e600f81e99c0f7085d122810c1a133dd6eb4217ab18b9b9d4ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.1

Release history Release notifications | RSS feed

This release

2.0.2 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page