easy-sock
A friendly, batteries-included wrapper around Python's built-in socket
module - with sensible message framing, timeouts, JSON helpers, file transfer
and a threaded server loop.
- No dependencies - standard library only
- TCP and UDP
- Length-prefixed, newline-delimited or raw framing
- Context-manager friendly
- Typed, with
py.typed
Installation
pip install easy-sock
Quick start
Echo server
from easy_sock import EasySocket
def handle(client, address):
print("connected:", address)
for message in client:
client.send(message)
server = EasySocket.server("0.0.0.0", 9000)
print("listening on", server.address)
try:
server.serve_forever(handle)
except KeyboardInterrupt:
server.stop()
finally:
server.close()
Client
from easy_sock import EasySocket
with EasySocket.connect_to("127.0.0.1", 9000) as sock:
sock.send("hello server")
print(sock.recv())
JSON messages
sock.send_message({"type": "ping", "id": 42})
reply = sock.recv_message()
Sending a file
sock.send_file("report.pdf")
path = sock.recv_file(destination="./downloads")
API overview
| Member | Description |
|---|---|
EasySocket(host, port, **opts) |
Create a socket |
EasySocket.server(host, port, **opts) |
Create a bound, listening TCP server |
EasySocket.connect_to(host, port, **opts) |
Create + connect a client |
.bind() / .listen() / .accept() |
Classic server calls |
.connect() |
Connect the client |
.send(data) / .recv() |
Send/receive one framed message |
.send_message(obj) / .recv_message() |
JSON helpers |
.send_file(path) / .recv_file(dir) |
File transfer |
.sendto(data, addr) / .recvfrom() |
UDP helpers |
.serve_forever(handler, max_connections=...) |
Threaded accept loop |
.settimeout(t) / .shutdown() / .close() |
Lifecycle |
.address / .peer / .closed / .socket |
Introspection |
Options
| Option | Default | Meaning |
|---|---|---|
protocol |
"tcp" |
"tcp" or "udp" |
timeout |
None |
Socket timeout in seconds |
buffer_size |
4096 |
Bytes read per recv() |
encoding |
"utf-8" |
Codec for str payloads |
framing |
"length" |
"length", "newline" or "raw" |
delimiter |
b"\n" |
Terminator for "newline" framing |
max_message_size |
64 MiB | Safety cap for a single message |
Exceptions
SocketEasyError
+-- ConnectionClosed
+-- SocketTimeout
+-- ProtocolError
Development
git clone https://github.com/yourname/easy-sock
cd easy-sock
python -m venv .venv
.venv\Scripts\activate
pip install -e ".[dev]"
pytest
Publishing
python -m build
twine check dist/*
twine upload dist/*
License
MIT (c) 2025 Your Name
Metadata
Release files for easy-socketer 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| easy_socketer-0.1.0.tar.gz | 11.4 kB | Without provenance | Details for easy_socketer-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| easy_socketer-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for easy_socketer-0.1.0-py3-none-any.whl |
Total release size: 21.0 kB
Release files / easy_socketer-0.1.0.tar.gz
| Download URL | easy_socketer-0.1.0.tar.gz |
|---|---|
| Size | 11.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d64227b9617c71f5400483c9a799195a802a0475fdb2849703de41db9160bf63
|
|
BLAKE2b-256 checksum How to use checksums |
e62f5eb5aaa4fa351fc8d5019400d24de4599beeb6e394b3dc76c20754a84552
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / easy_socketer-0.1.0-py3-none-any.whl
| Download URL | easy_socketer-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8533ab0e359f0372ba061f54cbfcf4f72f222a48d35ce5d8ba6feaf21e126167
|
|
BLAKE2b-256 checksum How to use checksums |
1d4fb6aabd66f78d2cdf57192a3577c7f19aa208a35ac4794d2fa993e0fbd4ee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Security for easy-socketer 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.