A lightweight WebSocket-based communication library
Project description
Lazy Socket
An attempt at creating a websocket based communication system that handles all the threading and async stuff in the background.
Installation
pip install lazy-socket
Usage
Server
The server can be created by subclassing LazyServer and implementing the process_message method. This is an async method that will be called whenever a message is received from a client. To respond to the client, use the send method of the client object passed to the method. A list of clients is available via the clients attribute of the server.
import asyncio
from lazy_socket.server import LazyServer
class Server(LazyServer):
async def process_message(self, client, message):
await client.send(f"Received: {message}")
if __name__ == "__main__":
server = Server(name="TestServer", host="0.0.0.0", port=5000, version="1.0")
try:
server.start()
except KeyboardInterrupt:
print("Shutting down server...")
Client
The client can be created by instantiating the LazyClient class. The client has a queue attribute that can be used to receive messages from the server. The client must be started using the start method. Messages can be sent to the server using the send method.
A message lazy_client:connected:{uri} is sent to the queue when the client successfully connects to the server.
from lazy_socket.client import LazyClient
client = LazyClient()
client.start()
while True:
if client.queue.empty():
continue
message = client.queue.get()
if message.startswith("lazy_client:connected:"):
client.send("Hello, Lazy Server!")
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 lazy_socket-0.0.2.tar.gz.
File metadata
- Download URL: lazy_socket-0.0.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df719076694be18bdf14868d1e31e7cc0e2d41e9b5515b0fb346c28b51308758
|
|
| MD5 |
4027e6f9e64dd724e5dcc24e14cda6ad
|
|
| BLAKE2b-256 |
7f9a2fee1f363a3c32d067488dbd13d992f3e44aafa90d0374db81b4ef0cdeaf
|
File details
Details for the file lazy_socket-0.0.2-py3-none-any.whl.
File metadata
- Download URL: lazy_socket-0.0.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68fd299fecd52485983aa22e193b4102650b41180af33ae65c71af1814dfc5a8
|
|
| MD5 |
26c0f8b968eb628f0658a956e5e434bf
|
|
| BLAKE2b-256 |
c32e0299c3057b00849e268468b03fc91ee53c72ce7acddb3c62b869ed508146
|