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.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| serialx-1.9.0.tar.gz | 706.4 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| serialx-1.9.0-py3-none-any.whl | Python 3 | none | any | Details |
| serialx-1.9.0-cp310-abi3-win_arm64.whl | CPython 3.10 | abi3 | Windows ARM64 | Details |
| serialx-1.9.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details |
| serialx-1.9.0-cp310-abi3-win32.whl | CPython 3.10 | abi3 | Windows x86-32 | Details |
| serialx-1.9.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| serialx-1.9.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 1.9 MB
Release files / serialx-1.9.0.tar.gz
| Download URL | serialx-1.9.0.tar.gz |
|---|---|
| Size | 706.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e9b35407e16afc6b14924191c327e49fe1c18ac5bfe5fcac0e41738d59959c49
|
|
BLAKE2b-256 checksum How to use checksums |
93384c562756c0850776115d56a4312fa26732d927200c43d44ea11d7c07bdb2
|
| 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 Aug 24, 2026.
Transparency logRelease files / serialx-1.9.0-py3-none-any.whl
| Download URL | serialx-1.9.0-py3-none-any.whl |
|---|---|
| Size | 73.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5c2861650d4938e51d7ace1abb452a35b105091e46108b6198c9b26cf3d218d4
|
|
BLAKE2b-256 checksum How to use checksums |
394287d302c790c133e5d76f5614a7cadf25f767e3198a5f468e9ffcea156d06
|
| 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 Aug 24, 2026.
Transparency logRelease files / serialx-1.9.0-cp310-abi3-win_arm64.whl
| Download URL | serialx-1.9.0-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 194.4 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b47ab9d9e6909fb6a3fe5003b41686c0f00d31c24d899c687bb67b31e1750abf
|
|
BLAKE2b-256 checksum How to use checksums |
153f62109f580b486f35d1f6bf4efd609711d950dadd69c35815c8d303d4fe62
|
| 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 Aug 24, 2026.
Transparency logRelease files / serialx-1.9.0-cp310-abi3-win_amd64.whl
| Download URL | serialx-1.9.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 197.8 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0cd1b34e8c18271b8e018620090522af190e1350a399e196bf0f2d319e1384ee
|
|
BLAKE2b-256 checksum How to use checksums |
c173c4ccb745d7827105c8cc283b65090f719bb7a0f980f19cc3e7c06f941679
|
| 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 Aug 24, 2026.
Transparency logRelease files / serialx-1.9.0-cp310-abi3-win32.whl
| Download URL | serialx-1.9.0-cp310-abi3-win32.whl |
|---|---|
| Size | 191.6 kB |
| Tags | CPython 3.10 Windows x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
1e0901c72fa32c1816476c9b14d00fa5a87b32cf9d29af79463daf9f835bcfd9
|
|
BLAKE2b-256 checksum How to use checksums |
e14e8a258bee101b3bf56e345dfdb721519b68adc471a864a3e3b6181d9c1de1
|
| 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 Aug 24, 2026.
Transparency logRelease files / serialx-1.9.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | serialx-1.9.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 287.7 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ea155dc9331946ad57bad9a5d18fa38eb2cefa9add6c9548703f0e97c3d68fac
|
|
BLAKE2b-256 checksum How to use checksums |
d33b4979a08a24447a84a51e47e66cbe0128e551913431bf1c87a7b0f3289391
|
| 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 Aug 24, 2026.
Transparency logRelease files / serialx-1.9.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | serialx-1.9.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 291.4 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
00560ccf342d56275f9c622b344105b1fc72cf69faee19a1fa66aa7d7acae23f
|
|
BLAKE2b-256 checksum How to use checksums |
f48c0339f60d85cc3adc488088027af10ca78bc0b0f0d03deaed9030dc723e25
|
| 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 Aug 24, 2026.
Transparency log