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-1.0.0.tar.gz (502.9 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.0.0-py3-none-any.whl (49.9 kB view details)

Uploaded Python 3

serialx-1.0.0-cp310-abi3-win_arm64.whl (50.3 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-1.0.0-cp310-abi3-win_amd64.whl (173.3 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-1.0.0-cp310-abi3-win32.whl (167.1 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-1.0.0-cp310-abi3-macosx_11_0_arm64.whl (268.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl (272.4 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for serialx-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5a062f975a099c1d78f2fc58a9d127718f84844a5c5ccc3e30b7ec6815a3e9f8
MD5 5387bb75360a73fe5255b643f8767082
BLAKE2b-256 5fcac5159b5dfb83a0271bf55b763dd9e6a416586e2a2f6798154099e1290058

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 49.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-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dd0977c12f076c9b6ac84e063ebd9e9d46d808fb493c854eb3fae48faeec30b5
MD5 ebf5127fd221ea0a5d2e058957066ce6
BLAKE2b-256 9924e35b90aa53e88625808d4ec6ea0873b5295445109dd3e2202b70eafbab0c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.0.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 50.3 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-1.0.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 ae85935b0cc9428fde033fc999836d9d53601882250a8c05fded1d0ebd4ea071
MD5 b05b64546e2e84a7880be2a06c9fbf1b
BLAKE2b-256 7fca6d9379238f7d4185a0464c6c83205a696dec2c1bd6c4ffbdcc9820849d0b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.0.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 173.3 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-1.0.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 902db572ed1d428dab8ba3c83400e12dab95427dc2073a9271c89ba9f204e711
MD5 11b7548b48719b8dad3f6b0b7b3093f8
BLAKE2b-256 e8ae8d172ee9bd8c8adae8e53bca51a7b98f2c791b3a6c1d1a6ff37e972c6651

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.0.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 167.1 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-1.0.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 e3fa4cf570c818de55d5d6547c8f71b7b66d0e5ae983b61fc6ce2a6fd0a86a79
MD5 ed23460d1472aaa453614d9419fddd8c
BLAKE2b-256 8267355316a90cc39391f12f962b45e65689571cc40d5cc922edfc8853c979ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-1.0.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 316e2d704ad113520c61609f82c153ae42b85c3137ef5634b7c1b03202de0fda
MD5 69fddb37149071b80695073d1ff81014
BLAKE2b-256 4236b4fe6acf44c10a6f6f4300466ea233c36b811a0a6042577941d3ace1416e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-1.0.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0cfc2dbd2fd444651cd3bfa761d80a9f83df85889a0dcb0f2c3ec3a246339a5a
MD5 f72bd8bb734257ae510400ea4e97ae6a
BLAKE2b-256 adfd0400ae2d6aab086048971388bd65d97fc0b24673c7173ea3844f2f5fcd6b

See more details on using hashes here.

Provenance

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