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_bits(rts=True, dtr=True)
    bits = serial.get_modem_bits()
    assert bits.rts is True
    assert bits.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_bits(rts=True, dtr=True)

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

Uploaded Source

Built Distribution

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

serialx-0.2.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for serialx-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c95cc0eeeed5ec6a1183cbb19d1dee0ae301d8fb5f3a73c2ed6fcc5d8ea46203
MD5 5998ceaf46db945d64040478f120e24e
BLAKE2b-256 ae9df5af0f8b662f1d58ece5269eb5cea48b1dbb68a125033d5c113cc02da127

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: serialx-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71bc26f3e933948b75747c1b20e63980793e4fd2393b3f600d2a62c7ee6694d6
MD5 046b27213b2750dd8fd61c6d41daae68
BLAKE2b-256 90b220c1727c9ee2b9fe61db75ac0bb5f3648a7f0ab8291edcf317e2e26da8ea

See more details on using hashes here.

Provenance

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

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