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.

Release files for serialx 1.10.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.10.0
File Size Uploaded
serialx-1.10.0.tar.gz 708.5 kB Details

Built distributions (wheels)

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

Total release size: 2.0 MB

Release files / serialx-1.10.0.tar.gz

Download URL serialx-1.10.0.tar.gz
Size 708.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9b69e8a31059bfbfff74186ea9da6790d0a21bb107451a833c10789e58aa368c
BLAKE2b-256 checksum
How to use checksums
ca181880d96ad54cf2e9ba381971c0c4e82e6d0f1e5024c6403de32936f41761
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 4, 2026.

Transparency log

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

Download URL serialx-1.10.0-py3-none-any.whl
Size 74.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
256712ba329d9ce0d1d08e0ddc6e9cd5d55784d15d47a70ea64f3610b37e8091
BLAKE2b-256 checksum
How to use checksums
6461da9aadc5cbdcf92a7fd8472489dd47c5a2e0f4d0bdf7c8a18efafe5dee44
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 4, 2026.

Transparency log

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

Download URL serialx-1.10.0-cp310-abi3-win_arm64.whl
Size 195.5 kB
Tags CPython 3.10 Windows ARM64 abi3
SHA-256 checksum
How to use checksums
97204439ecfb1881e0503201fef645771676b0ed07107ae329e161e3e5dc86c4
BLAKE2b-256 checksum
How to use checksums
0195578b0a3cc9cc7878733210fdeec0badc2766f780146c7455512280940f78
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 4, 2026.

Transparency log

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

Download URL serialx-1.10.0-cp310-abi3-win_amd64.whl
Size 198.9 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
7ef6639ff9dc47d47c6459876934eb5524d7199d090ed002328846b875f4604b
BLAKE2b-256 checksum
How to use checksums
bedd8ccdb032d6afe24cae51921a1283793b75a9f1affb63ac696f1de885771d
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 4, 2026.

Transparency log

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

Download URL serialx-1.10.0-cp310-abi3-win32.whl
Size 192.2 kB
Tags CPython 3.10 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
ce3f62cf43b9453656369463a436571c2100ba1adcd8a4007baaa0ea497b120f
BLAKE2b-256 checksum
How to use checksums
96f26e02e60b87da815b009ec3cd29d490ec62dddaadac5f55e50e380a99fba3
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 4, 2026.

Transparency log

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

Download URL serialx-1.10.0-cp310-abi3-macosx_11_0_arm64.whl
Size 288.8 kB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
f03549520c156fb18a0746ab20a4d3e0e4ce03d507213e561c5064d649f35206
BLAKE2b-256 checksum
How to use checksums
4cec045956b3daf493476014d253a7d1109aafba47575988e9e8c9239ebcd00e
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 4, 2026.

Transparency log

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

Download URL serialx-1.10.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 292.5 kB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
7ecc1dcbefbe6a98f8f03bbe54bb1020fdd060c42df2853baf84d1c88859d6de
BLAKE2b-256 checksum
How to use checksums
52b3c77018d4e9f25d871130a467e6afa3aa372f279a619b792e9ed87df45bf3
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 4, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.10.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