Skip to main content

No project description provided

Project description

Coverage CI Test suite

Package version

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smart_connection-0.1.0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

smart_connection-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

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

Hashes for smart_connection-0.1.0.tar.gz
Algorithm Hash digest
SHA256 eb0dc0f5da12a37ec9fc8273b8831d6c77b9fe734f7dd3b49a5ac5b664e85607
MD5 08bc5f9177d54c1c89ea1316e1b87688
BLAKE2b-256 a7fbcdfcf14f8c1b71bbdb57d3f84e2d9e5a29b19d94326de54259727fc37182

See more details on using hashes here.

File details

Details for the file smart_connection-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for smart_connection-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2894d3b8dab5a3a4535f6db5f680a6d09d9a33f94b2b6bc5d0dca96209b684f
MD5 2232ede7dbfbd1b83601cab1802b0bb9
BLAKE2b-256 706bb4ce5c08310c9d0ea03fb1670deded5055fc1b559c1391ee321e8ea22497

See more details on using hashes here.

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