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
Metadata
Release files for serio 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| serio-0.1.2.tar.gz | 10.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| serio-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.7 kB
Release files / serio-0.1.2.tar.gz
| Download URL | serio-0.1.2.tar.gz |
|---|---|
| Size | 10.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92c2efdda65e44ae0fb440e18546f94de39b39c547f0b07536ba47cee9658145
|
|
BLAKE2b-256 checksum How to use checksums |
2a10fb0d39da8afd40d55d1d92929a1bce5bb8c1c2f9b4cdf6c9b6d5a607e790
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / serio-0.1.2-py3-none-any.whl
| Download URL | serio-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8f3f2e34d9f2bb5415e3bf4dcca2698576c3829b3af39544e01974200845586b
|
|
BLAKE2b-256 checksum How to use checksums |
d9550c5fc391d8a6422e1d35fd0dc4d50acec14e1c1f2f8fc54e72debd20778e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for serio 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.