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 Alivecontrol - Default serializer works with
int, float, str, bytes, bytearray, list, dict, tuple, settypes - 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiosocketproto-0.0.14.tar.gz.
File metadata
- Download URL: aiosocketproto-0.0.14.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fed5f87a013dc1bc5970d6347763a5a3c02e315283126840792410d0af108c5
|
|
| MD5 |
936ed1638a6ba0f3105e9e20f69f4678
|
|
| BLAKE2b-256 |
871c5f2fab6e7ff3a379b3b0f8b6820c95c1dca83beb76aeb9f66f940c8b6b0d
|
File details
Details for the file aiosocketproto-0.0.14-py3-none-any.whl.
File metadata
- Download URL: aiosocketproto-0.0.14-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
002668a1196ae7f8589500fe5f8eb78d6350bb4faeee89bfbd3b7273f7a488f1
|
|
| MD5 |
cca656dc86ef273db05a8d8e789c256a
|
|
| BLAKE2b-256 |
caa8361f7f38d148acd4c6eb0c3c89760b5b6eb46befdd27be808e73ab04b6c6
|