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 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)

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-0.8.0.tar.gz (60.8 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.8.0-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

serialx-0.8.0-cp310-abi3-win_arm64.whl (33.2 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-0.8.0-cp310-abi3-win_amd64.whl (156.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-0.8.0-cp310-abi3-win32.whl (150.0 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-0.8.0-cp310-abi3-macosx_11_0_arm64.whl (251.0 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl (255.2 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for serialx-0.8.0.tar.gz
Algorithm Hash digest
SHA256 4bf5b6ee3f7e3df7e18626c177614af43bc7ee29478e6dc737a5dab99c853f46
MD5 e93aae76097c37d36dc689fd186bf2e9
BLAKE2b-256 57b9bc879fc60e7fda4e572190c0033cbc121544c8c44d4649f2671ebb7fdb1b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 32.9 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.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f0e2d8850aa2342a9d5f80441fafa4f6f2ee64ae7433facfc5fce089e3bea2e
MD5 12858ff6b6aeb1af9091f10c3784851c
BLAKE2b-256 93564ef29bd18972111542cc03d63ea891d98225a2e1d5f95d0197841ce97df1

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-0.8.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 33.2 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.8.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 c7d3bc3ff6bd7447a42faad9a88ebc03e2b6efde0c2b6a53d0bb9b942fd2ad7f
MD5 8d907046320e66546a30100d14d3b712
BLAKE2b-256 391a3852907cdef859897bdacfb4a13a5869403c95bb91f4b926b8e9e2e32953

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-0.8.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 156.1 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.8.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5154e13638635a27b66ec0f7662405f6c6602c1853967ae9ce3acfdcfe66a411
MD5 2ba84bc2a0b807d0e32d8a95e85826cd
BLAKE2b-256 67f81542c1778d737197b09e3aea09f99bd15d34753392b3ecdc10ebb4a7a50a

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-0.8.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 150.0 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.8.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 45b60d8181b1078bd8fcd5e1b2621bef32cb064a4f07adbda7a16b53eee348e9
MD5 4cdfbd7b0925d4155610dabbe830a665
BLAKE2b-256 17f159a16487f68625c87d4b807c248625dfd1af2b05f57815e97995ee33e703

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-0.8.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aafec3ad9dd3971458800372bd370b8168f71f27f094417826cc118c62ae879b
MD5 a0438a9a16a0afa92769ccb8458b40e5
BLAKE2b-256 6419369e7fd5458cbffe20df1e3b381849379d209895c0ca9a1ebed1fb285edd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-0.8.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d07fe878064262fc4f2e6634a799ca6ccae298abe8c68788a176c62a586ddef5
MD5 1e7b445e5dcd1654ccb28c3f89a4e944
BLAKE2b-256 65b9f6a5e6d7753accc3ebaab6048b94cce75a86dcdb47cbebaa574e37edf3ce

See more details on using hashes here.

Provenance

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