Skip to main content

Serial library with native sync and async support for Windows, Linux, macOS, and other platforms

Project description

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), install:

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

A high-level asynchronous serial (reader, writer) pair:

import asyncio
import contextlib

import serialx

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

	with contextlib.closing(writer):
	    data = await reader.readexactly(5)
	    writer.write(b"test")
	    await writer.drain()

And a low-level asynchronous serial transport:

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serialx-1.4.1.tar.gz (528.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

serialx-1.4.1-py3-none-any.whl (55.1 kB view details)

Uploaded Python 3

serialx-1.4.1-cp310-abi3-win_arm64.whl (174.8 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-1.4.1-cp310-abi3-win_amd64.whl (178.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-1.4.1-cp310-abi3-win32.whl (172.5 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-1.4.1-cp310-abi3-macosx_11_0_arm64.whl (271.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-1.4.1-cp310-abi3-macosx_10_12_x86_64.whl (273.5 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file serialx-1.4.1.tar.gz.

File metadata

  • Download URL: serialx-1.4.1.tar.gz
  • Upload date:
  • Size: 528.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serialx-1.4.1.tar.gz
Algorithm Hash digest
SHA256 8702d3e07d31ef26fbb23fbf223d7519a57e7fb0380f6c0715def01e2e4b9d27
MD5 d6a6ac90ca4b1dffbe2e58be996bd60d
BLAKE2b-256 32a974a66b7bc0192c80e4331107eb059041581f2002709526495b312b45728e

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1.tar.gz:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialx-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: serialx-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 55.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serialx-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6b8228af09bb94a1cd4a8d5da3c83257c8ed67dc3631a8c4e7094c207e9df040
MD5 3bd638dd0a737a1bda90715d8c92d3e4
BLAKE2b-256 ca8855f10540f68be35978502654598604ec17835ffaa2fa0e9d7381ce9436de

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1-py3-none-any.whl:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialx-1.4.1-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: serialx-1.4.1-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 174.8 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serialx-1.4.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 7a91a87c1ec2e5d850b363ebc911d1d11b6ca7f15a318e370c4e7087eb373a87
MD5 54ce713bef78d83c98a32cb9e9d9ee26
BLAKE2b-256 584770e2bf1c205c1528f6f3cca196c286785f30b43564b0795f2c737ccc7b07

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1-cp310-abi3-win_arm64.whl:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialx-1.4.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: serialx-1.4.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 178.5 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serialx-1.4.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 eb1ddf7568adc3b9d8018384fc031f93980ee77896bf49ebe0f290be41d5b90d
MD5 667d90e1cd3641a933867c2446382031
BLAKE2b-256 385b7384e3e0abd90aef7c5c2c2495107a0a849011a1c4c03b861bee44a3eb67

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1-cp310-abi3-win_amd64.whl:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialx-1.4.1-cp310-abi3-win32.whl.

File metadata

  • Download URL: serialx-1.4.1-cp310-abi3-win32.whl
  • Upload date:
  • Size: 172.5 kB
  • Tags: CPython 3.10+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for serialx-1.4.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 5ee6e9ae5447d5750e87e48dfc83a890f0acb5ea8a22a7e0e644438ce62d5784
MD5 6ceec38b0909495c0a7e0a1ddc7656cf
BLAKE2b-256 e4819f6db4f7d543e017b51d8ece3816679adfd8f4af831dd486370901ce1381

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1-cp310-abi3-win32.whl:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialx-1.4.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for serialx-1.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8967f3dc38dbfdf9ad9c4c9fff007c3952075d3a8159a43670ce8f23aa35910b
MD5 c7f88dc63e4e5e04d9edbb48efcecac1
BLAKE2b-256 a6c64a3338109d88779263d3820715792a3f48a3291f714ca5ea5ae19e4de06e

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file serialx-1.4.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for serialx-1.4.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 163b47caf5e7e51436571806bdd47108ef03d9c680c8f0cc4bfd86652e8fd47f
MD5 06eed682565cdf58835df84c8841ae4e
BLAKE2b-256 e55f11b68de11efbaecea9b5d8a17a974471184c2522393a117efd58f81984c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.4.1-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: publish-to-pypi.yml on puddly/serialx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page