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.15.tar.gz (8.0 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.15-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiosocketproto-0.0.15.tar.gz
  • Upload date:
  • Size: 8.0 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.15.tar.gz
Algorithm Hash digest
SHA256 0c3218da2aea65deeb99a1425d36a8f9f0a44a604cf65494c24718886aed0548
MD5 b2256fff126b8aad8c8d4bd52a49de61
BLAKE2b-256 da0ca6330a68eb903a021fb3b83a222564f9aae95d1f73cdcd7cba6cd592b036

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiosocketproto-0.0.15-py3-none-any.whl
Algorithm Hash digest
SHA256 ab586c89bf6afe6af7e0f18e99c2f299a7245cde00764fad5dada031b88faa31
MD5 3b6dac6feeadb1b0e16d486347c9944b
BLAKE2b-256 0874eccd79f67ec15be7657b3b7225a7de0c64c4cb70cbb18f7ebbb344dcd5d4

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