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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file virtual_term-2.0.0.tar.gz.
File metadata
- Download URL: virtual_term-2.0.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5342ef9b8a0f0dae488df14813a0d3f9ec1633860c47d6da4bd7deb9994b38fa
|
|
| MD5 |
47bfac13ad671046e8f92c0a16a8ce9a
|
|
| BLAKE2b-256 |
9da7f9d3f38bac95d3b0f634c3f1441e937007eb86aca4669808db61f97de082
|
File details
Details for the file virtual_term-2.0.0-py3-none-any.whl.
File metadata
- Download URL: virtual_term-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
887a43cc61477f00f4ff7c0cb0f5a90434238afe7f882c162169fc7757212339
|
|
| MD5 |
87c92c6654afec8a8c562f779657691b
|
|
| BLAKE2b-256 |
fe13f37f5c68ec4c4692a7740b078183c24df2058ac3e8f4ce3e398817eee7a2
|