No project description provided
Project description
Smart Connection
What is it?
Smart Connection (SC) is a a lightweight wrapper around asyncio TCP connection for building distributed systems. It provides a higher level API in the spirit of ZeroMQ.
Main features
Exchange message, not bytes
In contrast to TCP, which is a stream-oriented protocol, SC is a message-based protocol. This means that SC guarantees the delivery of each message as a distinct unit and in the correct order. In practice, each message is encapsulated within a frame that ensures its integrity. The protocol is simple and can be easily implemented in any other modern programming language.
User friendly API
Users can send and receive messages directly. Serialization and deserialization are handled transparently by the library. Messages can be received from a connection object using an async for loop, allowing for elegant user code.
A simple echo server example
Server
import asyncio
from smart_connection import Connection, wrap_server_connection_handler
@wrap_server_connection_handler
async def handle_connection(connection: Connection):
async for message in connection:
await connection.send(f"server replied: {message}")
async def main():
async with await asyncio.start_server(handle_connection, "127.0.0.1", 8888) as server:
await server.serve_forever()
Client
import asyncio
import aioconsole
from smart_connection import wrap_client_connection_handler
async def main():
connection_ends = await asyncio.open_connection("127.0.0.1", 8888)
async with wrap_client_connection_handler(connection_ends) as connection:
while True:
message = await aioconsole.ainput(">>> ")
await connection.send(message)
print(await connection.receive())
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 smart_connection-0.1.0.tar.gz.
File metadata
- Download URL: smart_connection-0.1.0.tar.gz
- Upload date:
- Size: 26.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb0dc0f5da12a37ec9fc8273b8831d6c77b9fe734f7dd3b49a5ac5b664e85607
|
|
| MD5 |
08bc5f9177d54c1c89ea1316e1b87688
|
|
| BLAKE2b-256 |
a7fbcdfcf14f8c1b71bbdb57d3f84e2d9e5a29b19d94326de54259727fc37182
|
File details
Details for the file smart_connection-0.1.0-py3-none-any.whl.
File metadata
- Download URL: smart_connection-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2894d3b8dab5a3a4535f6db5f680a6d09d9a33f94b2b6bc5d0dca96209b684f
|
|
| MD5 |
2232ede7dbfbd1b83601cab1802b0bb9
|
|
| BLAKE2b-256 |
706bb4ce5c08310c9d0ea03fb1670deded5055fc1b559c1391ee321e8ea22497
|