sockets
raw JSON → 1.0.0 verified Fri May 01 auth: no python
A lightweight Python package for creating simple servers and clients with sockets. Version 1.0.0 is the initial release. No active maintenance or release cadence observed.
pip install sockets Common errors
error ImportError: cannot import name 'server' from 'sockets' ↓
cause Older versions or incorrect installation; package may not expose 'server' directly.
fix
Reinstall:
pip install --upgrade sockets and verify version >= 1.0.0. error TypeError: server.serve() missing 1 required positional argument: 'handler' ↓
cause The `handler` parameter is required but omitted.
fix
Call
server.serve(host, port, handler_func) with a callable that accepts one argument (connection socket). Warnings
gotcha The library is extremely minimal; it provides only `server` and `client` modules with basic functions. Do not expect advanced features like async, SSL, or automatic reconnection. ↓
fix For production use, consider asyncio's streams or the standard library `socket` module directly.
gotcha The `server.serve` function blocks forever; you must run it in a separate thread or process if you need to do other work. ↓
fix Use threading: `threading.Thread(target=server.serve, args=(host, port, handler)).start()`
Imports
- server
from sockets import server - client
from sockets import client
Quickstart
from sockets import server, client
def handle_client(conn):
data = conn.recv(1024)
print("Received:", data.decode())
conn.sendall(b"Hello from server")
conn.close()
# Run server in background (example)
import threading
t = threading.Thread(target=server.serve, args=('localhost', 9999, handle_client))
t.start()
# Client example
client.send('localhost', 9999, "Hello server")