anyserial¶
Low-latency async serial I/O for Python, built on AnyIO.
Pre-release
anyserial is in active development. The API is not yet stable.
Features¶
- Async-native via AnyIO — asyncio, uvloop, trio.
- Python 3.13+, tested on 3.13 and 3.14.
- POSIX first-class (Linux, macOS, BSD) via
SyncSerialBackend; Windows first-class viaAsyncSerialBackendwith native IOCP dispatch. - Low-latency by design — O(μs) per syscall, O(ms) pty round-trips.
- Raw bytes only — compose with
anyio.streams.buffered.BufferedByteStreamfor framing. - Explicit capabilities, runtime reconfiguration, RS-485 on Linux.
- Sync wrapper for scripts and test benches.
Install¶
Optional extras:
uv add "anyserial[uvloop]" # faster asyncio loop on POSIX
uv add "anyserial[trio]" # trio support
uv add "anyserial[discovery-pyudev]" # Linux udev-sourced metadata
uv add "anyserial[discovery-pyserial]" # cross-platform discovery fallback
30-second tour¶
import anyio
from anyserial import SerialConfig, open_serial_port
async def main() -> None:
config = SerialConfig(baudrate=115_200)
async with await open_serial_port("/dev/ttyUSB0", config) as port:
await port.send(b"AT\r\n")
reply = await port.receive(64)
print(reply)
anyio.run(main)
Scripts that don't want an event loop can use the sync wrapper:
from anyserial.sync import SerialPort
with SerialPort.open("/dev/ttyUSB0", baudrate=115_200) as port:
port.send(b"AT\r\n")
print(port.receive(64, timeout=1.0))
Where to next¶
- Quickstart — open a port, send, receive, test.
- Configuration — every
SerialConfigfield. - Capabilities — what
SUPPORTED/UNKNOWN/UNSUPPORTEDmean and how to gate features on them. - Cancellation — how
SerialPortcomposes with AnyIO cancel scopes. - Runtime reconfiguration, RS-485, Discovery.
Runtime¶
- AnyIO backend selection — asyncio vs. uvloop vs. trio.
- uvloop usage — when it helps, when it doesn't.
- Performance — targets, measured numbers, methodology.
Platforms¶
- Linux tuning — permissions,
low_latency, custom baud, udev rules. - macOS —
IOSSIOSPEED, IOKit discovery, unsupported-feature routing. - BSD — FreeBSD / NetBSD / OpenBSD / DragonFly; best-effort.
- Windows —
AsyncSerialBackend, overlapped I/O, ProactorEventLoop requirement, SetupAPI discovery.
Development¶
- Sync wrapper — blocking
SerialPortfor scripts. - Hardware testing — opt-in markers, FTDI loopback wiring.
- Troubleshooting — permission errors, EINVAL on baud, exclusive-access conflicts.
- Migration from pySerial — API mapping and behaviour diffs.
Status¶
See the changelog and the full design plan.