Skip to main content

Serial library with native async support for Windows and POSIX

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.

Installation

pip install serialx

Usage

Serialx features a pyserial and pyserial-asyncio compatibility layer for easy testing. As early as possible, run serialx.patch_pyserial() and it will provide API-compatible replacements.

import serialx
serialx.patch_pyserial()

# These will now use serialx
import serial
import serial_asyncio

Serialx features a familiar synchronous API:

import serialx

with serialx.Serial("/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 True
    assert pins.dtr is True

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)

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. We do not have a custom GitHub Actions runners with real hardware (yet) so GitHub Actions CI will only run socat tests.

To run tests locally with loopback adapters and pairs of real adapters, pass CLI flags to pytest:

pytest --loopback-adapter=/dev/serial/by-id/my-loopback-adapter \
       --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, this will run tests in parallel across all adapter pairs. You can disable this by passing -n 0 to pytest, which will execute the tests sequentially.

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-0.7.0.tar.gz (46.3 kB view details)

Uploaded Source

Built Distributions

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

serialx-0.7.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

serialx-0.7.0-cp310-abi3-win_arm64.whl (25.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-0.7.0-cp310-abi3-win_amd64.whl (149.5 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-0.7.0-cp310-abi3-win32.whl (142.6 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-0.7.0-cp310-abi3-macosx_11_0_arm64.whl (244.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl (248.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for serialx-0.7.0.tar.gz
Algorithm Hash digest
SHA256 615eb0b30aaf5b454dfe22d4995aa6a5003e5a2933feb69878b839625912ad91
MD5 e2620c9bdb012c8a894ca6661f9bd5ee
BLAKE2b-256 2ac0c646ad9936d21db2015e87e7828a13f745d47f34c8065c48782db547598f

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for serialx-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57111dceda2af63fed472cae8a7c1457334209651cf01b9dcba4cdc4640795a4
MD5 15c13ca9d6fca8516cce8d8b4b5a6980
BLAKE2b-256 9bff78aa8debcb7accea9ba0553b7d30be6125d9d41196785ffd3a3301448cdd

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for serialx-0.7.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 42a5333bdddfa2b5f4b9ac96a85a0e3ec627706cc633e5527fab4ee190877227
MD5 832f1b8ccbac9aa197b5ba00f081ed84
BLAKE2b-256 b3e357dbab7491c2d445d4d350a26c51a2f09369a19519b9ca96065b080a7d07

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for serialx-0.7.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 303de70f524ba6e1ac1dc9bcc5e4d1986e1593ce23bbbb7e99dbefacd7202626
MD5 3e61d7ceaa9459abec431ae21cf5894b
BLAKE2b-256 6a532d7c39664795a54cb367283f4b14b4f96657d15b13dab78939abe517be23

See more details on using hashes here.

Provenance

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

File metadata

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

File hashes

Hashes for serialx-0.7.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 2c41db477078e0dac874f94b957a0320624a06a11e5b4afff035f51514786be2
MD5 5dc298455d8dd9c73d24b39da2f9c5c6
BLAKE2b-256 a43bfc796bb0613d7b5c5e0d49142a94b9f3151a73a0bfa7ad07828733efed6b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9a05cd88010062047f712cb415d070aa1169327f14e555d15ab37dfeb47c6eef
MD5 36a868ea84d0b897ee410175f1e2332d
BLAKE2b-256 ec5b6afc3893f16198aec0f6760b51f8540e5096f881a2338cc7de566cb53650

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-0.7.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5715a282be100b658c98f36960a4e0a6a93692cad48bae51c61e6026339a8231
MD5 8611062e424e9db22787d2610df39b96
BLAKE2b-256 85c940e28ec761239d9a65f27ab1fe8366de642b60b1b5ed90af67ddcc80608f

See more details on using hashes here.

Provenance

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