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.0.tar.gz (507.1 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.0-py3-none-any.whl (54.7 kB view details)

Uploaded Python 3

serialx-1.1.0-cp310-abi3-win_arm64.whl (173.6 kB view details)

Uploaded CPython 3.10+Windows ARM64

serialx-1.1.0-cp310-abi3-win_amd64.whl (178.1 kB view details)

Uploaded CPython 3.10+Windows x86-64

serialx-1.1.0-cp310-abi3-win32.whl (172.0 kB view details)

Uploaded CPython 3.10+Windows x86

serialx-1.1.0-cp310-abi3-macosx_11_0_arm64.whl (273.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

serialx-1.1.0-cp310-abi3-macosx_10_12_x86_64.whl (277.7 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: serialx-1.1.0.tar.gz
  • Upload date:
  • Size: 507.1 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.0.tar.gz
Algorithm Hash digest
SHA256 e27092ff2ab0311868f32ef4da55b8adf497cc21f45ed389f295155b46964cca
MD5 4ccf823f61779af2e69d5b111d8ef941
BLAKE2b-256 dc4b4d20f4714328b0721ba33e119f80be475ce581788507c73893043abaede5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 54.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 409a7a403eee4eea8ff1b960a9229cc6d2a6b2ee9b316dd7f943ecdb1731ce82
MD5 46c027f09ae133b43c6baed4effba916
BLAKE2b-256 737a29709841d9349bd146fb535aa15f936703b0d4958d0fde44b79217b689de

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.0-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 173.6 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.0-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 cbe321228edc7aa23268c0468edfada455017f5eaf1cd676b99f5535d53e8edc
MD5 c833399d33e3dd245a13f6f33e41cda8
BLAKE2b-256 f9db1fea5e8a87be8581fe6b1cd9a757d7cfc9dde564929d7f98868fd16c9725

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.0-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 178.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-1.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 219606dfe71c88d7509cd6802b0d80007fb828442c011655cf41d4747d1abece
MD5 1fca79101b083153102fe292680252ec
BLAKE2b-256 55411a091639133e383460155327aa99b0ba6bed3f328338894d5af3146b3a05

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-1.1.0-cp310-abi3-win32.whl
  • Upload date:
  • Size: 172.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-1.1.0-cp310-abi3-win32.whl
Algorithm Hash digest
SHA256 2a2d8073c31c66d561726fa4b8011b0ebdf0a39093c649947d0d34be54758dae
MD5 5bdc299ffc619517e2cdd249c8c52595
BLAKE2b-256 0e8587211b9adf2c71a530fcb86d51d25ab12c339824d15c46697534fbd3f0d0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-1.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c3451674b6c5244d714c1feda5103820aa78a0cdef4aeeb502a521b2c2d6970e
MD5 d1cae5d5c4ad3f08541ebfcd2a1d6035
BLAKE2b-256 c5f79084435997a5a51bd7bb469c966dab0e9ff51129ce2fb4791866ef8d9ef6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for serialx-1.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 0a04ee38cd78d7784e7764907ca549376afca292a0ded5af2e3c8b7a9e67011e
MD5 87b05047ad5d82bb5a804f57ba0f9d59
BLAKE2b-256 2e95f654dff752a6261e1df1528ded0f44b0fff8970df1954131df6f553d5fc8

See more details on using hashes here.

Provenance

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