Lightweight, stdlib-only TCP IPC bridge with length-prefixed JSON, loopback-by-default, auth tokens, allowlist, max-bytes cap, and protocol versioning.
Project description
SocketBridge
Lightweight, stdlib-only TCP IPC bridge for local agents and tools.
Features
- Length-prefixed JSON frames (no partial or merged reads)
- Loopback-by-default bind
- Auth token + host allowlist
- Max-bytes cap and protocol version check
- Zero dependencies (pure Python stdlib)
Quick Start (once published)
pip install socketbridge
from socketbridge.server import SocketServer
def handler(message):
print("got", message)
srv = SocketServer("127.0.0.1", 7002, handler=handler)
srv.start()
# ... send messages with an auth_token ...
srv.stop()
Client helper (planned):
from socketbridge.client import send
resp = send("127.0.0.1", 7002, {"type": "ping"}, token="secret")
print(resp)
Examples
examples/example_server.py— minimal server that echos back notifications.examples/example_client.py— sends a JSON payload with optional auth token.
Run them:
python examples/example_server.py &
python examples/example_client.py --text "hello" --token secret
Security Defaults
- Binds 127.0.0.1 unless you override host
- Optional auth token via
SOCKETBRIDGE_TOKEN - Optional allowlist via
SOCKETBRIDGE_ALLOWLIST(comma separated) - Payload cap via
SOCKETBRIDGE_MAX_BYTES(default 1MB) - Not for internet-facing use without additional hardening (TLS/mTLS)
Architecture (conceptual)
Client
|
| 4-byte length + JSON (auth_token, protocol_version, payload)
v
SocketBridge Server (loopback, token/allowlist/max-bytes)
|--> handler(message) # your code runs here
|
^ 4-byte length + JSON response (status, message, protocol_version)
Mermaid sequence (for docs that render it):
sequenceDiagram
participant C as Client
participant S as SocketBridge
participant H as Handler
C->>S: send(len+JSON payload)
S->>S: validate host/token/version/size
S->>H: handler(message)
H-->>S: (optional) side effects
S-->>C: len+JSON response (status/protocol)
Why
Provides a clean side-band channel for agents, test harnesses, and helper processes without touching stdout/stderr or adding external dependencies.
License
MIT
Project details
Release history Release notifications | RSS feed
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 socketbridge-0.1.0.tar.gz.
File metadata
- Download URL: socketbridge-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cac64e114b6636a318198265519a1fb70b3f1673c275a75c3b1e25c50a1bf227
|
|
| MD5 |
2f666abd4c1bb013b1d6c747ada3876a
|
|
| BLAKE2b-256 |
bf993e19a26ae71113e1b94196d0fc21df1a2d0da7a05d51678769b817003d79
|
File details
Details for the file socketbridge-0.1.0-py3-none-any.whl.
File metadata
- Download URL: socketbridge-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3005b7d0527aa62b20871b973acdc9d5bed970eba6c461f9246891550be69874
|
|
| MD5 |
fa284014978a9b8f3d5220d3fe446c9b
|
|
| BLAKE2b-256 |
6f58dc79acaca68cd58994bebeb1374081cf2517ee1d232f031e2f25092c82d1
|