pexpect
termKept in this browser · My desk
A pure Python module, modelled on Expect, that spawns a program on a pseudo-terminal, waits for patterns in its output and sends it input.
It brought Expect's model to the language most network automation is now written in, with the same habits and a few traps of its own: a timeout that raises an exception after 30 seconds where Expect carries on after 10, a sendline that ends with a linefeed where a device documents the Enter key, and a $ that its documentation calls useless for finding the end of a line. Ansible's expect module requires it.
Also known as: python expect, pexpect.spawn
Sources
- Pexpect documentation, API Overview: a pure Python module for spawning child applications, controlling them and responding to expected patterns in their output, which works like Don Libes' Expect; TIMEOUT after 30 seconds by default; sendline appends a linefeed (read 2026-10-27)
- pexpect on PyPI: release 4.9.0 of 25 November 2023, ISC licence (read 2026-10-27)