pexpect-serial
pexpect with pyserial
What it is and what it does
pexpect-serial adapts the pexpect library—which automates interactive terminal sessions—to work with serial ports managed by pyserial. Instead of controlling a subprocess or SSH session, you pass an open serial.Serial connection and use the same expect/sendline pattern-matching API to interact with serial devices. This is useful for automating communication with embedded systems, microcontrollers, or any device connected via serial that responds to text commands.
The package is minimal and straightforward: you open the serial port yourself using pyserial, wrap it in SerialSpawn, then use pexpect's familiar send and expect methods to script the interaction. The responsibility for opening, closing, and configuring the serial connection remains with the caller.
Use it for:
- Automate testing of firmware or bootloader behavior on embedded devices over serial.
- Script interactive setup or configuration sequences for serial-connected hardware.
- Build regression tests for serial protocol implementations or device command responses.
- Automate repetitive serial console interactions (e.g., device provisioning or diagnostics).
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extends pexpect to work with serial ports by wrapping pyserial connections, allowing you to send commands and match responses over serial communication.
Yes, if you need pexpect-style pattern matching over serial and are comfortable with an unmaintained package. The code is simple and the dependencies are stable, so it is unlikely to break immediately. However, verify compatibility with your current pexpect and pyserial versions, and be prepared to fork or patch if issues arise. Not recommended for new projects requiring ongoing support.
Install
pexpect-serial on PyPI
pip
pip install pexpect-serialuv
uv add pexpect-serialpoetry
poetry add pexpect-serialInstalling pexpect-serial
Before you install
Low install friction with only two runtime dependencies (pexpect and pyserial). However, the package is abandoned—last commit was 2021-05-18 and no releases since 2019-08-10. It remains archived but not actively maintained.
License in practice
MIT license is permissive and poses no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
import serial
from pexpect_serial import SerialSpawn
with serial.Serial('COM1', 115200, timeout=0) as ser:
ss = SerialSpawn(ser)
ss.sendline('start')
ss.expect('done')
You must open and manage the serial.Serial connection yourself before passing it to SerialSpawn; the package does not handle port lifecycle.
Verify before relying
- Whether pexpect and pyserial versions currently available are compatible with this 0.1.0 release.
- Whether the package works reliably with modern Python versions (3.9+) despite being unmaintained since 2019.
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pexpect, pyserial |
| Maintenance | abandoned — 2,561 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 105,104/month — #12,720 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pexpect_serial-0.1.0-py3-none-any.whl
Tags
More Terminals packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
richRich renders styled text, tables, progress…
permissive · top 100 on PyPI
coloramaColorama makes ANSI escape sequences for…
permissive · top 100 on PyPI
wcwidthMeasures the displayed width of Unicode strings…
permissive · top 1,000 on PyPI
ptyprocessRun a subprocess in a pseudo terminal (pty) and…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
xmodemImplements the XMODEM file transfer protocol…
permissive · top 15,000 on PyPI
pyserial-asyncioAdds async/await support to pyserial for…
permissive · top 15,000 on PyPI
aioserialProvides async/await serial port I/O using…
copyleft · top 15,000 on PyPI
serialxSerialx provides synchronous and native…
permissive · top 15,000 on PyPI
types-pyserialProvides type hints for the pyserial library,…
permissive · top 5,000 on PyPI
pyserial-asyncio-fastProvides async I/O support for serial port…
permissive · top 15,000 on PyPI
types-pexpectProvides type stubs for pexpect, enabling type…
permissive · top 5,000 on PyPI
delegator.pyDelegator.py wraps subprocess execution with a…
permissive · top 15,000 on PyPI
binho-host-adapterControls Binho Multi-Protocol USB Host Adapters…
permissive · top 15,000 on PyPI