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.2.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.2-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiosocketproto-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 757d9b6a43635f0494992a348b9a22da3be27db7edffa13ab25ce106d5d5a740
MD5 2ca2e5b104960f3e7c9aabde087774f8
BLAKE2b-256 45ffd0ba83eac70edc33d6791efe2cb7738bb178e29e4c270de2df575642d18c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiosocketproto-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for aiosocketproto-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6ac3917c315df8f152311258b094122e26b813cb22d2db8ecf204267f5d585f6
MD5 b45881d6d767b6344b0ad4263b11653b
BLAKE2b-256 24f0f16921d446454ae16bdfd5b5d538f52ce5a85f0b2560f301160456e2a736

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