Skip to main content

Introduction

Serialx is a no-compromise serial communication library for Python targeting common platforms such as Linux (POSIX), macOS, and Windows. It provides both synchronous and native asynchronous APIs for all platforms.

For more information, visit serialx's documentation: https://puddly.github.io/serialx/

Installation

pip install serialx

For drop-in import compatibility (serial, serial_asyncio, serial_asyncio_fast) in environments where existing code cannot be migrated:

pip install serialx-compat

Usage

Serialx features a familiar synchronous API:

import serialx

with serialx.serial_for_url("/dev/serial/by-id/port", baudrate=115200) as serial:
    data = serial.readexactly(5)
    serial.write(b"test")

    serial.set_modem_pins(rts=True, dtr=True)
    pins = serial.get_modem_pins()
    assert pins.rts is serialx.PinState.HIGH
    assert pins.dtr is serialx.PinState.HIGH

An async equivalent of the synchronous API:

import asyncio
import serialx

async def main():
    async with serialx.async_serial_for_url(
        "/dev/serial/by-id/port", baudrate=115200,
    ) as serial:
        data = await serial.readexactly(5)
        await serial.write(b"test")

        await serial.set_modem_pins(rts=True, dtr=True)
        pins = await serial.get_modem_pins()
        assert pins.rts is serialx.PinState.HIGH

A (StreamReader, StreamWriter) pair is also available for code already wired up to the asyncio streams API:

import asyncio
import serialx

async def main():
    reader, writer = await serialx.open_serial_connection(
        "/dev/serial/by-id/port", baudrate=115200,
    )

    try:
        data = await reader.readexactly(5)
        writer.write(b"test")
        await writer.drain()
    finally:
        writer.close()
        await writer.wait_closed()

And a low-level asynchronous serial transport for protocol-style consumers:

import asyncio
import serialx

async def main():
    loop = asyncio.get_running_loop()
    protocol = YourProtocol()

    transport, protocol = await serialx.create_serial_connection(
        loop,
        lambda: protocol,
        url="/dev/serial/by-id/port",
        baudrate=115200,
    )

    await transport.set_modem_pins(rts=True, dtr=True)

ESPHome serial proxy

Serialx can communicate with serial devices exposed by ESPHome.

It can either create the API instance directly, for simplicity:

from serialx import open_serial_connection

reader, writer = await open_serial_connection(
    url="esphome://192.168.1.42:6053/?port_name=Zigbee&key=...",
    baudrate=115200,
)

Or reuse an existing API instance, for efficiency:

from aioesphomeapi import APIClient
from serialx import open_serial_connection
from serialx.platforms.serial_esphome import ESPHomeSerialTransport

# An external API instance
api = APIClient(address="192.168.1.42", port=6053, key="...", password=None)
await api.connect(login=True)

reader, writer = await open_serial_connection(
    url=None,
    transport_cls=ESPHomeSerialTransport,
    api=api,
    port_name="Zigbee",
    baudrate=115200,
)

Development

All development dependencies are listed in the dev dependency group in pyproject.toml. To install them into a .venv (activate it afterwards, or prefix commands with uv run), use:

uv sync

On macOS and Windows, a Rust toolchain is required to build the native serial port enumeration extension. Install Rust via rustup.

Set up pre-commit hooks with prek install. Your code will then be type checked and auto-formatted when you run git commit. You can do this on-demand with prek run.

Serialx relies on automated testing. CI runs tests using both socat virtual PTYs (Linux/macOS) and socket-based serial pairs. To also test with physical adapter pairs, pass CLI flags to pytest:

pytest --adapter-pair=/dev/serial/by-id/left1,/dev/serial/by-id/right1 \
       --adapter-pair=/dev/serial/by-id/left2,/dev/serial/by-id/right2

Each test runs once, on any one of the pairs. More pairs let more pytest-xdist workers run adapter tests at once.

By default, tests run in parallel. You can disable this by passing -n 0 to pytest.

Metadata

Release files for serialx 1.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for serialx 1.13.0
File Size Uploaded
serialx-1.13.0.tar.gz 385.3 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for serialx 1.13.0
File
serialx-1.13.0-py3-none-any.whl Python 3 none any Details
serialx-1.13.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
serialx-1.13.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
serialx-1.13.0-cp310-abi3-win32.whl CPython 3.10 abi3 Windows x86-32 Details
serialx-1.13.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
serialx-1.13.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 1.7 MB

Release files / serialx-1.13.0.tar.gz

Download URL serialx-1.13.0.tar.gz
Size 385.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0f9ecfb157ff04beb280cd01fce6cca36a5092af861dbb31072e636bd3b8f547
BLAKE2b-256 checksum
How to use checksums
07a8aec21f8a6d23be84a9dd9eb9259f3f2feec2b5169eefb2fd647d3a14d5e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / serialx-1.13.0-py3-none-any.whl

Download URL serialx-1.13.0-py3-none-any.whl
Size 86.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9ad3d26f89f54d864e84d25ca94eb380845a8033d9a5c8fcf284be377a44a8e
BLAKE2b-256 checksum
How to use checksums
d675479d56a6d94c948d7a1f2f5527db0646be06828391d9770c216853dfd0c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / serialx-1.13.0-cp310-abi3-win_arm64.whl

Download URL serialx-1.13.0-cp310-abi3-win_arm64.whl
Size 207.6 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
f92e19a17ea707bda2d046297df01152447cfc36c3b31bd18e9eb9e103a7d03e
BLAKE2b-256 checksum
How to use checksums
35c5454f44eeecc2ce6fab52ab8ba3d796ebc9c97be279c2ba0b7dc7dcfec535
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / serialx-1.13.0-cp310-abi3-win_amd64.whl

Download URL serialx-1.13.0-cp310-abi3-win_amd64.whl
Size 211.1 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
1c29bcb8f95882a3446f1beaac4956ab467e513544a0b7d254d3f77443d005f1
BLAKE2b-256 checksum
How to use checksums
faeff0a4331559d62a91853fad03c2e69a3d3f4843507fa3d97a1ebd8bba2d4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / serialx-1.13.0-cp310-abi3-win32.whl

Download URL serialx-1.13.0-cp310-abi3-win32.whl
Size 203.7 kB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
f99157898d2e57fdc6aa31d4dbca0f6025ef46f077a87adaf626a10ba7c14df5
BLAKE2b-256 checksum
How to use checksums
2b9000694b7d5adbcc82d407b9d03e3dda6f4ca6dc47dc24b5baeb114b461132
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / serialx-1.13.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL serialx-1.13.0-cp310-abi3-macosx_11_0_arm64.whl
Size 300.7 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e167d396444e3eaeded493db8ded6dc2ef222c94df3acea8b1c35d9f3013da03
BLAKE2b-256 checksum
How to use checksums
478d0ff0ec5faf1ea3b24002d3a617cc99c968bbef96501883f62d3813a12481
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / serialx-1.13.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL serialx-1.13.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 304.7 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7a99a643ce2ce69e25d4e4657dfa227a699483b67948becc0c2ebf3502b0c3d0
BLAKE2b-256 checksum
How to use checksums
1c0f663693df3beb252249f4c02f1d1c03ce1fa6a461cdd826884f1ef6377fc0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

1.14.0

7 release files

This release

1.13.0 This release

7 release files

1.12.0

7 release files

1.11.0

7 release files

1.9.0

7 release files

1.8.2

7 release files

1.8.1

7 release files

1.8.0

7 release files

1.7.3

7 release files

1.7.2

7 release files

1.7.1

7 release files

1.7.0

7 release files

1.6.0

7 release files

1.5.0

7 release files

1.4.1

7 release files

1.4.0

7 release files

1.3.0

7 release files

1.2.3

7 release files

1.2.2

7 release files

1.2.1

7 release files

1.2.0

7 release files

1.1.1

7 release files

1.1.0

7 release files

1.0.0

7 release files

0.8.0

7 release files

0.7.0

7 release files

0.5.0

22 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page