Modern asynchronous serial port library for Python 3.11+
Project description
Serio: Modern Asynchronous Serial Communication Library
Serio is a modern asynchronous serial port library for Python 3.11+ that provides efficient, native async I/O without thread pool overhead. It offers both high-level streams API and low-level transport API for serial communication.
Features
- ✅ True async I/O (no thread pool overhead)
- ✅ Python 3.11+ native support
- ✅ Clean, modern API with asyncio integration
- ✅ POSIX and Windows support
- ✅ High-level Streams API (StreamReader/StreamWriter)
- ✅ Low-level Transport API for custom protocols
- ✅ Platform-optimized async I/O (polling on Windows, file descriptors on POSIX)
- ✅ Proper flow control with buffer management
- ✅ Comprehensive exception handling
Installation
pip install serio
Getting Started
High-Level API Example
import asyncio
from serio import open_serial_connection
async def main():
reader, writer = await open_serial_connection(
port='/dev/ttyUSB0',
baudrate=115200
)
writer.write(b'AT\r\n')
response = await reader.readuntil(b'\r\n')
print(f"Received: {response.decode()}")
asyncio.run(main())
Low-Level API Example
import asyncio
from serio import create_serial_connection
class MyProtocol(asyncio.Protocol):
def connection_made(self, transport):
print("Connection established")
def data_received(self, data):
print(f"Received: {data}")
def connection_lost(self, exc):
print("Connection closed")
async def main():
loop = asyncio.get_running_loop()
transport, protocol = await create_serial_connection(
loop,
MyProtocol,
port='/dev/ttyUSB0',
baudrate=115200
)
transport.write(b'AT\r\n')
await asyncio.sleep(1)
transport.close()
asyncio.run(main())
Context Manager Example
from serio import SerialStream
async def main():
async with SerialStream(port='/dev/ttyUSB0', baudrate=115200) as (reader, writer):
writer.write(b'AT\r\n')
response = await reader.readuntil(b'\r\n')
print(f"Received: {response.decode()}")
asyncio.run(main())
API Reference
High-Level API
open_serial_connection(**kwargs) -> (StreamReader, StreamWriter)create_serial_connection(loop, protocol_factory, **kwargs) -> (SerialTransport, Protocol)SerialStream(**kwargs)- Context manager for serial connections
Low-Level API
SerialTransport(loop, protocol, serial_instance)- Asynchronous serial transportSerialError- Base exception classSerialConnectionError- Raised when connection failsSerialConfigError- Raised for invalid configurationPlatformNotSupportedError- Raised for unsupported platforms
Configuration Parameters
| Parameter | Description | Default |
|---|---|---|
port |
Serial port name (e.g., /dev/ttyUSB0 or COM3) |
None |
baudrate |
Baud rate | 9600 |
bytesize |
Data bits | serial.EIGHTBITS |
parity |
Parity checking | serial.PARITY_NONE |
stopbits |
Stop bits | serial.STOPBITS_ONE |
timeout |
Read timeout (seconds) | None |
xonxoff |
Software flow control | False |
rtscts |
Hardware (RTS/CTS) flow control | False |
write_timeout |
Write timeout (seconds) | None |
dsrdtr |
Hardware (DSR/DTR) flow control | False |
inter_byte_timeout |
Inter-character timeout | None |
exclusive |
Exclusive access mode | None |
Platform Support
- POSIX: Uses file descriptors for true async I/O
- Windows: Uses efficient polling (5ms intervals)
- Unsupported: Other platforms will raise
PlatformNotSupportedError
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit pull requests or open issues.
Author: Semenets V. Pavel
Version: 0.1.2
Email: p.semenets@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file serio-0.1.2.tar.gz.
File metadata
- Download URL: serio-0.1.2.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92c2efdda65e44ae0fb440e18546f94de39b39c547f0b07536ba47cee9658145
|
|
| MD5 |
e6e83536af11c372587f02a61ba98ae1
|
|
| BLAKE2b-256 |
2a10fb0d39da8afd40d55d1d92929a1bce5bb8c1c2f9b4cdf6c9b6d5a607e790
|
File details
Details for the file serio-0.1.2-py3-none-any.whl.
File metadata
- Download URL: serio-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f3f2e34d9f2bb5415e3bf4dcca2698576c3829b3af39544e01974200845586b
|
|
| MD5 |
024aab7e1432373ea89864c8dc62c3c5
|
|
| BLAKE2b-256 |
d9550c5fc391d8a6422e1d35fd0dc4d50acec14e1c1f2f8fc54e72debd20778e
|