Skip to main content

ShellIO is a Python interface for interacting with Unix-like shells

Project description

shellio

ShellIO is a Python interface for interacting with Unix-like shells (sh, bash, zsh) using pseudoterminals (PTY). It enables real-time communication with interactive shell processes, capturing and parsing output including ANSI escape sequences.

Features

  • ✅ Spawn interactive shell sessions (sh, bash, zsh)
  • 📤 Send input directly to the shell (stdin)
  • 📥 Read output instantly using PTY — no line buffering delay
  • 🧩 Detect and split ANSI escape sequences from raw output
  • 🧼 Automatically terminates all shell processes on exit
  • 🧵 Background threading for non-blocking output reading
  • 🔀 Supports multiple concurrent shell instances

Use Cases

  • Terminal emulators
  • Shell automation tools
  • Output parsers
  • Teaching/debugging shell interactions

Instalation

$ pip install shellio

Example of usage:

from shellio import ShellIO

# Initialize a new shell object
shell = ShellIO('bash', []) # zsh, sh or bash

# You can specify a path where to start the shell
shell.set_cwd('.')

# Start the process
shell.run()

# Clear last output file
open('output.txt', 'w').close()

# Put the first command with a return
shell.put('ls -la\n')

# Wait a second for output
shell.wait(2)

# Put the second command
shell.put('touch works.txt\n')

# Read all bytes from shell and save it to a file
for b in shell.get(timeout=0.01):
    print(b.decode(), end='')
    with open('output.txt', 'a') as file:
        file.write(b.decode())

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

shellio-1.0.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

shellio-1.0.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: shellio-1.0.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for shellio-1.0.1.tar.gz
Algorithm Hash digest
SHA256 67a6abae0cfb9ed3d9896df82510f3276e3c4cdb32f67f63072155f39cea1a46
MD5 1423ddaa69b4cac9e7b0d7e8446d8e1b
BLAKE2b-256 0bfc4631dbf863b8288d1a43f1cc25984ab179b5c58c2bc2aa5f99112ca7d189

See more details on using hashes here.

File details

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

File metadata

  • Download URL: shellio-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for shellio-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3e3b017865418728b44f76d1737c960d0142407491c81fcee2bda53916b57b1
MD5 6f06bc535a88429709a2b0025248cff0
BLAKE2b-256 781358078d2c5d4d06c00617b05047038a4dd5c0525bdc041f2878e677fa86b9

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