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&noise_psk=...",
    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, noise_psk="...", 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.2.3.tar.gz (518.4 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.2.3-py3-none-any.whl (66.0 kB view details)

Uploaded Python 3

serialx-1.2.3-cp310-abi3-win_arm64.whl (185.1 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-1.2.3-cp310-abi3-win_amd64.whl (189.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-1.2.3-cp310-abi3-win32.whl (183.4 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-1.2.3-cp310-abi3-macosx_11_0_arm64.whl (284.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-1.2.3-cp310-abi3-macosx_10_12_x86_64.whl (289.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for serialx-1.2.3.tar.gz
Algorithm Hash digest
SHA256 5d11963e2ba3fc412fff52f75e8b46e60efd4913a5208716f7079a2e07d5cfb0
MD5 4698d82e0ee1c08faddfbd66e6b86888
BLAKE2b-256 b63dcec0f21bddaf6fe30cf6af1d5136274fc054dca6a15eb9eb788bde812f64

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3.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.2.3-py3-none-any.whl.

File metadata

  • Download URL: serialx-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 66.0 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.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8bc5ef7766199f576939fdaa48eed3abd3d4480bc6f229da5c5a97a3d9e56ef7
MD5 4eb2907d90f8cb79d74b2d5c8616aa4c
BLAKE2b-256 9dbafd3b8e249ba2048bc2e5bf2d4caaeff3d48ae25e3ce80969934319dab09e

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3-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.2.3-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: serialx-1.2.3-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 185.1 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.2.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 6ffb41ecf1a86a6568e12c21d09738e357da9132058e047733822d68e6565f66
MD5 85ad2e011f0df184d8ccf5e79ee29d81
BLAKE2b-256 93febdf6010e7fc5c17eed8f4881eae06031c895b09043b834c979bdb8740ce6

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3-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.2.3-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: serialx-1.2.3-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 189.6 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.2.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 737c1a047e3370fa34c89f651e96eb57e12612b994dfc7396f6a82d5b0058bf3
MD5 38106d96a94887e3d5d67b32d036dd06
BLAKE2b-256 8b0d1c5399a96da77be85a78f972357c746e3523d0e50e90da0e45a88fd7631a

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3-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.2.3-cp310-abi3-win32.whl.

File metadata

  • Download URL: serialx-1.2.3-cp310-abi3-win32.whl
  • Upload date:
  • Size: 183.4 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.2.3-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 c2209a2d99aa057bf0d51cfebb314ccb84df96c94b403eb6c7df956fe83e39cd
MD5 2ce0ab92f9d1b57db0ab856d5f973b45
BLAKE2b-256 11d55e7794069fec93489c9dd99fbd0a4a7831b9b23037fbfd9185865f4ee4ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3-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.2.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for serialx-1.2.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b983fbce0d47c5b59c49e9e600fa74b00f1cf5567a5abf69e685da13bb800d1e
MD5 8ae9893a24a0c67c5641c1d2e1de665b
BLAKE2b-256 719d0f75f8592aaeca117e279a51402db4032025b73c011f4aa7116b8edc7990

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3-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.2.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for serialx-1.2.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 31537757be90be385573bb05701b7cf45056f90ffad2b2592665374da1defd3b
MD5 e48e10dd33022695eeb220b48fc148fa
BLAKE2b-256 bc22085fd2e25063161eb2f8f59d9b9c0695d3e96e3dc04f455a62c7c7ae50d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for serialx-1.2.3-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