Skip to content

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 via AsyncSerialBackend with native IOCP dispatch.
  • Low-latency by design — O(μs) per syscall, O(ms) pty round-trips.
  • Raw bytes only — compose with anyio.streams.buffered.BufferedByteStream for framing.
  • Explicit capabilities, runtime reconfiguration, RS-485 on Linux.
  • Sync wrapper for scripts and test benches.

Install

uv add anyserial
# or
pip install anyserial

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

Runtime

Platforms

  • Linux tuning — permissions, low_latency, custom baud, udev rules.
  • macOSIOSSIOSPEED, IOKit discovery, unsupported-feature routing.
  • BSD — FreeBSD / NetBSD / OpenBSD / DragonFly; best-effort.
  • WindowsAsyncSerialBackend, overlapped I/O, ProactorEventLoop requirement, SetupAPI discovery.

Development

Status

See the changelog and the full design plan.