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 pyproject.toml. To install them, use:

uv pip install '.[dev]'

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 pre-commit install. Your code will then be type checked and auto-formatted when you run git commit. You can do this on-demand with pre-commit 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

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

Metadata

Release files for serialx 1.11.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.11.0
File Size Uploaded
serialx-1.11.0.tar.gz 318.4 kB Details

Built distributions (wheels)

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

Total release size: 1.6 MB

Release files / serialx-1.11.0.tar.gz

Download URL serialx-1.11.0.tar.gz
Size 318.4 kB
Tags Source
SHA-256 checksum
How to use checksums
38a4b60212d994449c9f3314c523ec629f1ccf629f4767b3867c7a5381366ab9
BLAKE2b-256 checksum
How to use checksums
9bc58c3f3e7985ca108fab641cc453ae015e1f6f15344064b99f115281c8bbdc
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 Sep 29, 2026.

Transparency log

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

Download URL serialx-1.11.0-py3-none-any.whl
Size 85.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e9b67771a1211cdb41716c8fbefe1775e4b3db51dc3495dceb8e46ce13883479
BLAKE2b-256 checksum
How to use checksums
245bf48f5776eacb254f074d1468a9879c7c3b2cb3ba2980719baed82a437d1b
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 Sep 29, 2026.

Transparency log

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

Download URL serialx-1.11.0-cp310-abi3-win_arm64.whl
Size 206.2 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
6862f5b5b6570bdae0e0957fa71b27a95848126f5be8ea55235a076d0ffbc7f6
BLAKE2b-256 checksum
How to use checksums
cd7dee26eea6411d76690a482117dec33397a4a721379e065c3229e027daee51
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 Sep 29, 2026.

Transparency log

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

Download URL serialx-1.11.0-cp310-abi3-win_amd64.whl
Size 209.3 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
802104900deb97748cbeaacfeff22ebde471e2ec3ba5e7aae5d1ae48c8c19515
BLAKE2b-256 checksum
How to use checksums
6c46c124a469670c9c85968b3e4b64d848f7cc8c219b542e38828ae48e08b94b
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 Sep 29, 2026.

Transparency log

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

Download URL serialx-1.11.0-cp310-abi3-win32.whl
Size 202.6 kB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
e1363618d88f04645eb211a197d5d8e74985bb1045d00007b12546f7c9ce36d5
BLAKE2b-256 checksum
How to use checksums
f5cb14e2b32d452d7dada6c4a31262637b7f2f6fe0afce58a901b5cf1dd4d3e6
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 Sep 29, 2026.

Transparency log

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

Download URL serialx-1.11.0-cp310-abi3-macosx_11_0_arm64.whl
Size 299.1 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
8f4c067c3fe53ddc5125dd95959e60939f3d923e198710481070154974cb81e3
BLAKE2b-256 checksum
How to use checksums
91ff7dfe95c42aa68cc74fd0eb28accb3821d58856badffda3505aff77046c87
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 Sep 29, 2026.

Transparency log

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

Download URL serialx-1.11.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 302.8 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
66da2fed65ffe6b557e1b670041df139faadb21d752510c406c72e12c3ab86c3
BLAKE2b-256 checksum
How to use checksums
69e8bc14ca3e1b663f7196560e60ad1664864a11ee87f4ef5bb69cbc67c31002
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 Sep 29, 2026.

Transparency log

Release history Release notifications | RSS feed

1.14.0

7 release files

1.13.0

7 release files

1.12.0

7 release files

This release

1.11.0 This release

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