ptyprocess
Run a subprocess in a pseudo terminal
This package has a good security score with no known vulnerabilities.
Community Reviews
Functional but bare-bones PTY handling with minimal operational controls
The lack of built-in timeout controls on read operations is immediately noticeable. You'll need to implement your own timeout logic with select/poll or wrap everything in threading.Timer constructs. There's no connection pooling concept (not really applicable here), but more critically, no resource cleanup helpers or context managers in the base class. You must explicitly call close() and terminate() or risk leaving zombie processes and open file descriptors.
Error handling is minimal - exceptions bubble up from the OS level without much wrapping or context. When a child process dies unexpectedly, you get raw errno values to interpret. The library hasn't seen updates since 2020, and while it's stable, you're on your own for any edge cases. For simple interactive automation it works, but for production workloads, expect to build significant scaffolding around it.
Best for: Simple terminal automation scripts where you're building your own robust wrapper with proper timeout and cleanup logic.
Avoid if: You need production-ready PTY handling with timeouts, retries, and resource management out of the box - consider pexpect which builds on this.
Low-level PTY interface with minimal security guardrails
The API is straightforward but error handling is minimal. Failed spawns and closed PTYs can raise cryptic OSError exceptions that don't always clearly indicate whether it's a permission issue, file not found, or PTY allocation failure. The library hasn't been updated since 2020, which is concerning given its low-level nature - no CVE response history to evaluate, but also no active maintenance if issues emerge.
For security-sensitive applications, you need to layer significant validation on top. The spawn() method takes command arguments but doesn't prevent shell injection if you're constructing commands from user input. There's no built-in sandboxing, resource limiting, or timeout mechanisms - you implement everything yourself.
Best for: Building terminal emulators or automation tools where you fully control all inputs and need low-level PTY access.
Avoid if: You're processing untrusted input or need built-in security guardrails and active maintenance.
Functional but bare-bones PTY library with minimal developer experience
The documentation exists but is sparse, consisting mainly of API reference without practical examples or common use case patterns. Error messages are often cryptic low-level POSIX errors that don't guide you toward solutions. You'll frequently encounter `OSError` exceptions without helpful context about what went wrong with your PTY setup.
In practice, most developers should reach for `pexpect` instead, which wraps ptyprocess and provides a much better interface. You'd only use ptyprocess directly if you're building your own PTY abstraction or need minimal dependencies. The lack of maintenance since 2020 is concerning - no Python type stubs, no modern ergonomics, just the bare essentials.
Best for: Building custom PTY abstraraction layers or when you need absolute minimal dependencies.
Avoid if: You need rich terminal interaction features, type safety, or good documentation - use pexpect instead.
Sign in to write a review
Sign In