simio
Python simple lightweight zero-dependency asynchronous IO library.
Motivation
Python 3.4 introduced native support for asynchronous code and announced asyncio standard library. async/await syntax provided a very convenient way to write single-threaded concurrent code but asyncio library itself caused a lot of pain to developers since it was ugly designed and provides very inconvenient api and asynchronous primitives. To fix that problem developers implemented some third-party libraries to replace the standard one like trio.
You may use trio or anyio, but trio implements its own runtime, anyio although work on top of asyncio but provides too high level interface which may be undesirable for small projects.
This library is intended to solve some of that tensions.
Features
- Buffered streams
- TCP stream
- TCP server
Installation
You can install simio with pip:
pip install simio
Quickstart
Buffered stream:
import asyncio as aio
from simio import net, stream
async def main() -> None:
async with await net.open_tcp_stream(
address=net.IPv4Address("httpforever.com", 80),
socket=net.TcpSocketInet(),
) as http_stream:
buffered_stream = stream.BufferedStream(http_stream)
await buffered_stream.write_all(
b'GET / HTTP/1.1\r\n'
b'Host: httpforever.com\r\n'
b'\r\n',
)
status = await buffered_stream.read_until(b'\r\n')
print(status.decode())
headers = await buffered_stream.read_until(b'\r\n\r\n')
headers = dict(line.split(b':', maxsplit=1) for line in headers.removesuffix(b'\r\n\r\n').split(b'\r\n'))
body = await buffered_stream.read_exactly(size=int(headers[b'Content-Length']))
print(body.decode())
aio.run(main())
Echo TCP server:
import asyncio as aio
import logging
from simio import net
async def echo(socket: net.TcpSocket[net.IPv4Address]) -> None:
data = await socket.recv(1024)
await socket.sendall(data)
async def main() -> None:
logging.basicConfig(level=logging.INFO)
await net.start_tcp_server(
net.IPv4Address("127.0.0.1", 8080),
srv_socket=net.TcpSocketInet(),
handler=echo,
graceful_shutdown=10.0,
)
aio.run(main())
TCP client stream:
import asyncio as aio
from simio import net
async def main() -> None:
async with await net.open_tcp_stream(
address=net.IPv4Address("127.0.0.1", 8080),
socket=net.TcpSocketInet(),
) as tcp_stream:
await tcp_stream.write(b"Hello World!!!")
while data := await tcp_stream.read(1024):
print(data)
aio.run(main())
TLS client stream:
import asyncio as aio
from simio import net, stream, tls
async def main() -> None:
hostname = "www.wikipedia.org"
async with await net.open_tcp_stream(net.IPv4Address(hostname, 443), socket=net.TcpSocketInet()) as tcp_stream:
async with tls.open_tls_stream(tcp_stream, server_side=False, server_hostname=hostname) as tls_stream:
http_stream = stream.BufferedStream(tls_stream)
await http_stream.write_all(
b'GET / HTTP/1.0\r\n'
b'Host: www.wikipedia.org\r\n'
b'User-Agent: simio\r\n'
b'\r\n',
)
status = await http_stream.read_until(b'\r\n')
print(status.decode())
raw_headers = await http_stream.read_until(b'\r\n\r\n')
headers: dict[bytes, bytes] = {}
for line in raw_headers.removesuffix(b'\r\n\r\n').split(b'\r\n'):
key, value = line.split(b':', maxsplit=1)
headers[key.lower()] = value.lstrip()
body = await http_stream.read_exactly(size=int(headers[b'content-length']))
print(body.decode())
aio.run(main())
Metadata
Release files for simio 1.2.0
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 | Actions |
|---|---|---|---|---|
| simio-1.2.0.tar.gz | 12.9 kB | Without provenance | Details for simio-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simio-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for simio-1.2.0-py3-none-any.whl |
Total release size: 30.2 kB
Release files / simio-1.2.0.tar.gz
| Download URL | simio-1.2.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38264992bba5f6c5d2de79f13bfe695dd6702738714651ddf7c61b9bc7ec4b9b
|
|
BLAKE2b-256 checksum How to use checksums |
410cb79f3949d09f800444e921244c69d4402bce4cac7fe0c03b55646a955bf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.14.4 Linux/6.17.0-1010-azure
|
Release files / simio-1.2.0-py3-none-any.whl
| Download URL | simio-1.2.0-py3-none-any.whl |
|---|---|
| Size | 17.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ce5669cb4be03e88f0f875914cc8504cdfbb23e8ab827f9b747ea410d93cd309
|
|
BLAKE2b-256 checksum How to use checksums |
846804717641b498ce328d5761604f935b165135f0d3b3fa6d00d8dfaad687f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.4 CPython/3.14.4 Linux/6.17.0-1010-azure
|
Security for simio 1.2.0
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.