Skip to main content

A simple and universal socket protocol written in Python

Project description

Async Socket Protocol

Just Simple and Universal socket protocol written in Python.

After writing the socket protocol class for the tenth time, I wanted to make a universal package for all my projects. I will be glad to support and advice!

Features

  • Client side
  • Server side
  • Safe Kepp Alive control
  • Default serializer works with int, float, str, bytes, bytearray, list, dict, tuple, set types
  • Ability to easily add your own serializers

How To Install

Just use pip from your command line:

pip install aiosocketproto

How To Use

Create server

import asyncio
import aiosocketproto


async def connection(socket: aiosocketproto.AsyncSocketClient):
    print('Client connected!')
    await server.receive()
    await server.send(data='example str data')


async def create_server():
    server = await aiosocketproto.start_server([9999], connection)
    await server.idle() # keep alive


asyncio.run(create_server())

In this case, the server will be launched at 0.0.0.0:9999 You can pass a range of ports (example: range(8888, 9999)), and the server will choose the first available one.

Connect as client

import asyncio
import aiosocketproto


async def connect():
    server = await aiosocketproto.connect('127.0.0.1', 9999)
    await server.send(data=[123, 'abc', b'somebytes'], second_arg=0.123)
    await server.receive()


asyncio.run(connect())

Full example with custom serializers see in example.py

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

aiosocketproto-0.0.13.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

aiosocketproto-0.0.13-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file aiosocketproto-0.0.13.tar.gz.

File metadata

  • Download URL: aiosocketproto-0.0.13.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for aiosocketproto-0.0.13.tar.gz
Algorithm Hash digest
SHA256 355e3058f0e47e467140e879a156837e08fef774e30c412ee466dbf3211e4263
MD5 c80c8809bffd9fa6681b5cc760057ba9
BLAKE2b-256 c43abb55ba3ebe6bcbb6c81caa3159f8152c1f61765d27b944cb4855e7368cc3

See more details on using hashes here.

File details

Details for the file aiosocketproto-0.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for aiosocketproto-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 962a18553435570c390b0bcc9fc517931a0e315aa66b90b498e2a2ac64ce955c
MD5 3cc920f79aa19b918ec21e9b7178f959
BLAKE2b-256 a92a2234f4ebbba77d8f8adff3bc7cb1318c32b1108e05f9f34e523b8b2cdf08

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