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.11.tar.gz (6.6 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.11-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiosocketproto-0.0.11.tar.gz
  • Upload date:
  • Size: 6.6 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.11.tar.gz
Algorithm Hash digest
SHA256 c5d93c5d536c61ac30a1871570fbaa773d4527fb44f933b716c76230c0166683
MD5 caad7d3749a410487e1257f19ae034fe
BLAKE2b-256 34a0af2afbf7a0295da4b7c8739c3566d99483e1efd2d7358280728b0ce506b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for aiosocketproto-0.0.11-py3-none-any.whl
Algorithm Hash digest
SHA256 c148f90e2ce53e5027cd092c51e92939eafd2d83395cb970688777c06dbeec78
MD5 dd0cd4b4c37072564ba97cfb45891e1c
BLAKE2b-256 809a0aaaea61e3f7d9cc14bd78cf719521482435a96ae5d9b11b4313b05ed356

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