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.14.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.14.0
File Size Uploaded
serialx-1.14.0.tar.gz 389.9 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for serialx 1.14.0
File
serialx-1.14.0-py3-none-any.whl Python 3 none any Details
serialx-1.14.0-cp310-abi3-win_arm64.whl CPython 3.10 abi3 Windows ARM64 Details
serialx-1.14.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
serialx-1.14.0-cp310-abi3-win32.whl CPython 3.10 abi3 Windows x86-32 Details
serialx-1.14.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
serialx-1.14.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.14.0.tar.gz

Download URL serialx-1.14.0.tar.gz
Size 389.9 kB
Tags Source
SHA-256 checksum
How to use checksums
508fbc83290b2c368cc3cc034bc2a30fa083d1bdcfae6755a1175f6ec14c8af1
BLAKE2b-256 checksum
How to use checksums
1946a23c683d997c5d46f34e777abb7f4b0e41e189b115a9f6995812e404595c
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 14, 2026.

Transparency log

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

Download URL serialx-1.14.0-py3-none-any.whl
Size 86.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a88be02fd4318ee94fe2408edeb5322766c729a95dd318c366c0b8f7ece6338
BLAKE2b-256 checksum
How to use checksums
def97f8040d02baa571b166ac33699316d90ec542871897864b4e909bb7d52fa
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 14, 2026.

Transparency log

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

Download URL serialx-1.14.0-cp310-abi3-win_arm64.whl
Size 207.9 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
c8f66e56e0e20ecc4814c170a68a1db0f3ca9ff7cf0dc66dce170f522865bd2e
BLAKE2b-256 checksum
How to use checksums
1a831ae90731ca0ff5fa51c82c995343d9d7ca7c686a829a1d403b046694329c
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 14, 2026.

Transparency log

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

Download URL serialx-1.14.0-cp310-abi3-win_amd64.whl
Size 211.3 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
63836a6844bd8bad5cf360738cbd701e0b32681c111976fccebd470fd55673d3
BLAKE2b-256 checksum
How to use checksums
463311fd18e60b96b96f639cac4e2a3167bf994fce66f89c2f806393736e3332
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 14, 2026.

Transparency log

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

Download URL serialx-1.14.0-cp310-abi3-win32.whl
Size 204.0 kB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
82e2a598b89b4b00412725ed52f65b3961f6617029a2333f63c27c9fb08c1497
BLAKE2b-256 checksum
How to use checksums
1788c617a715950da6ea540b986de3e494f1d99e9d4b9720ba691c68fe520b9d
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 14, 2026.

Transparency log

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

Download URL serialx-1.14.0-cp310-abi3-macosx_11_0_arm64.whl
Size 301.0 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
90c38eddd655397842a8c3593e4cdb164ff7508bab3fb17e932188f8d0582b6f
BLAKE2b-256 checksum
How to use checksums
41e927727800c21dccc90cf605cd5ec68adefdf5d779cfe5bbe2391546ef45d0
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 14, 2026.

Transparency log

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

Download URL serialx-1.14.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 304.9 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
921ef0991d73e9fc99fec18af95e627c7771356589d5dc1f5b2574b686c03ec7
BLAKE2b-256 checksum
How to use checksums
e8b608d578a8ab5eaea9fa1276a0b4f8e74fa5453ee82128544ecfbd3ae6c139
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 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.14.0 This release

7 release files

1.13.0

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