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

For drop-in import compatibility (serial, serial_asyncio, serial_asyncio_fast) without runtime patching, install:

pip install serialx-compat

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.1.1.tar.gz (507.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.1.1-py3-none-any.whl (55.0 kB view details)

Uploaded Python 3

serialx-1.1.1-cp310-abi3-win_arm64.whl (173.9 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-1.1.1-cp310-abi3-win_amd64.whl (178.4 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-1.1.1-cp310-abi3-win32.whl (172.3 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-1.1.1-cp310-abi3-macosx_11_0_arm64.whl (273.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-1.1.1-cp310-abi3-macosx_10_12_x86_64.whl (278.0 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for serialx-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ceb30f558ceafd3597ca2f7507b7e94a818c3b0b4e5d357ffdfb4b121bfb530b
MD5 565eacb7d04463ad73f55dec8de51686
BLAKE2b-256 5d9f092b09e9bec3245f17e94a53afb7d0e345916584881abcc21ed478a2031b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 55.0 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.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 560329461d3555ed73ea6ca8aa8338f2a4adc1b371b1d3d7da8f04d0e29c7b27
MD5 926846ecb151ca92129d18f0f4330caf
BLAKE2b-256 d194e76736553b2c7c954b5e5c9c5beb14c5f9317837e728003d0133cd0d4b4f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.1-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 173.9 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.1.1-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 063ca1bb73978672c192bb7613640e52c15c89635d8a857986b35b6b57c49d88
MD5 d403f205d544c484b4a83a324eec44ff
BLAKE2b-256 549ed824dbb24a30e1ddbba495ee3c3676f7bbda07d4d9f1919c8fcbc225947f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 178.4 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.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f539042fedd9ebd962fc718775bf4c41bb2bdd38b9f195aefebf0530fc0cca76
MD5 b58c00a4fd8f33e178bfa0c69d257974
BLAKE2b-256 79dc5ec43abc060b60964505a9d41e36cab8588cf8142f08650df515f08dd616

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.1-cp310-abi3-win32.whl
  • Upload date:
  • Size: 172.3 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.1.1-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 7fd6adec3e91e9d822bb34b4ba10fe7bfd12f9b40b10a0bedf367036055d6f37
MD5 4f29872d002b03a4dafd528b0fd9c51b
BLAKE2b-256 7cde2f2511ec845d67e4d1da3228ec146e82264e859596d756231345ed4005a2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-1.1.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1dee170dfa76eca6956a7534d4b3a8a5b5c976c714e3c7779e3fca6d0ba33b80
MD5 99371c70c3a7d7557ad078c94652e6b3
BLAKE2b-256 cf4c8d944f4a6cda9beca9b5b39fe25313abcf3b6b0092cf27d01bc566d93d64

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-1.1.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a9958238af73e856fc6d380ab06e7cecd35e8d2d8b2a66762e551d6edcb0a891
MD5 db01860500b786a09f0e09afa084bb29
BLAKE2b-256 be8e9b955dd44556e89e18e0f6fcf88631a52851f65ab492e82bbaa82b3762e8

See more details on using hashes here.

Provenance

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