Skip to main content

A performant asynchronous communication protocol in pure Python.

Project description

A performant asynchronous communication protocol in pure Python.

This library was developed with simplicity and performance in mind, with modern practices of Python development.

Documentation Reference

Install

Works on Python 3.8.0+.

pip install sayd

Development

You need to have installed poetry for dependencies management (how to).

git clone https://github.com/lw016/sayd
cd sayd
poetry install

Run tests

poetry run tox -e tests

Build docs

poetry run tox -e docs

Features

  • Client and server implementations

  • Reliable TCP persistent connection

  • Auto reconnection (client)

  • Multiple asynchronous connections (server)

  • Blacklist of clients (server)

  • TLS encryption

  • Proxy Protocol V2 support (server)

  • Data transmitted as dictionaries (json)

  • Broadcast (server)

  • Remote function callbacks

  • Built-in CLI utility to generate self-signed certificates

Roadmap

  • Add support to Unix socket

  • Implement TLS certificate authentication

CLI

The built-in CLI utility (sayd) can be used to generate self-signed certificates to encrypt the connection.

sayd --help

Usage example

Server

import logging
import asyncio

from sayd import SaydServer


logging.basicConfig(
        format="[%(name)s][%(levelname)s] %(asctime)s - %(message)s",
        datefmt="%Y/%m/%d %H:%M:%S"
        )

logger = logging.getLogger("SERVER")
logger.setLevel(logging.INFO)


server = SaydServer(logger=logger)


@server.callback("message")
async def msg(address: tuple, instance: str, data: dict) -> dict:
    return {"greetings": "Hello from server!"}


async def main() -> None:
    await server.start()


    while True:
        result = await server.call("msg", {"greetings": "Hi!"}) # Broadcast call.
        print(result)

        await asyncio.sleep(1)


    await server.stop()


if __name__ == "__main__":
    asyncio.run(main())

Client

import logging
import asyncio

from sayd import SaydClient


logging.basicConfig(
        format="[%(name)s][%(levelname)s] %(asctime)s - %(message)s",
        datefmt="%Y/%m/%d %H:%M:%S"
        )

logger = logging.getLogger("CLIENT")
logger.setLevel(logging.INFO)


client = SaydClient(logger=logger)


@client.callback("msg")
async def msg(instance: str, data: dict) -> dict:
    return {"greetings": "Hello from client!"}


async def main() -> None:
    await client.start()


    while True:
        result = await client.call("message", {"greetings": "Hi!"})
        print(result)

        await asyncio.sleep(1)


    await client.stop()


if __name__ == "__main__":
    asyncio.run(main())

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

sayd-1.2.9.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

sayd-1.2.9-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file sayd-1.2.9.tar.gz.

File metadata

  • Download URL: sayd-1.2.9.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for sayd-1.2.9.tar.gz
Algorithm Hash digest
SHA256 1715263de4cf68b5963f773c18d0aa6c31438410f9b140608fade48ed1c496ca
MD5 cc8e99512bcfd2fdbe4304d67a933b94
BLAKE2b-256 32383204165597cc0cf2982026557fcb89b2f0e54c707be4bcbf791084fe5e9d

See more details on using hashes here.

File details

Details for the file sayd-1.2.9-py3-none-any.whl.

File metadata

  • Download URL: sayd-1.2.9-py3-none-any.whl
  • Upload date:
  • Size: 17.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for sayd-1.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 72955e1e104701c59970cceeb969754a4923eb93c3a815305a041738582a74f8
MD5 8121d58776c169239b8705b8fb8c049e
BLAKE2b-256 53885684a5773757723cb79cd2c274f4c82e0c4f60ea5f84f887eea1588e50dd

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