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

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiosocketproto-0.0.12.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.12.tar.gz
Algorithm Hash digest
SHA256 100e0f59c0f9210506deaab5d6ea2b36370c08b725f849486941584b59819571
MD5 a002ccd91bdfb76bee845bec58e68634
BLAKE2b-256 fc7f7d20592ab75cb3c4c64236d719219b0bb4a6d55cdffaae3ee0ae6bfac419

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiosocketproto-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 e0b5fadc39157c12c2a8016b7af78b808f1ab8cd857e91a6e3f8d2147cb96cac
MD5 97fddb80764a3b0dcb8fdfe04001971d
BLAKE2b-256 ddb0f744b4035f590742a8cae6e7b4043a52e97e98f81917e06b41ac38690d8d

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