flux
Dead-simple sockets for Python. Events, rooms, auto-JSON, heartbeats, reconnection, and one port that serves both plain TCP and WebSocket (browser) clients. No dependencies.
from flux import Server
server = Server(5000)
@server.on("connect")
def connect(client): print(client.id, "connected")
@server.on("move")
def move(client, data):
server.broadcast("moved", {"id": client.id, **data})
server.run()
from flux import Client
client = Client("localhost", 5000)
@client.on("moved")
def moved(data): print(data)
client.emit("move", {"x": 100, "y": 50}) # queued until connected
client.run() # or client.start() for a background thread
Browser: <script src="flux.js"> then new Flux("ws://localhost:5000") — same .on / .emit.
API
Server(port=5000, host="0.0.0.0", heartbeat=15, timeout=45)
.on(event) · .auth · .room(name) · .broadcast(event, data, exclude=None) · .run() · .start() · .stop() · .clients
Special events: connect, disconnect, message (raw/non-envelope input, e.g. from nc), * (everything: client, event, data).
Handlers can take fewer arguments: def join(client) is fine.
Server client: .id .name .data .rooms .kind ("tcp"/"websocket") · .send(data) / .send(event, data) / .emit(event, data) · .join(room) .leave(room) · .close()
Room: .emit(event, data, exclude=None) · .join(c) .leave(c) · .clients · len(room)
Auth: @server.auth def check(client, token): return token == "..." and Client(..., token="...").
Clients that fail (or don't authenticate within 10s) are dropped; connect only fires after success.
Client(host, port, token=None, reconnect=True) — .on .emit .run() .start() .wait_connected() .close() .id
Wire format
TCP: one JSON per line. WebSocket: one JSON per text frame. Shape: {"event": "name", "data": ...}.
Anything else arrives as a message event, so nc localhost 5000 works for poking around.
Not yet
UDP, asyncio API, Python-side WebSocket client, TLS. Handlers run on per-connection threads, so guard shared state with a lock.
Try it
python -m unittest discover -s tests
python examples/cubes_server.py # then open examples/cubes.html in two tabs
Metadata
Release files for flux-sockets 0.6.5
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 |
|---|---|---|---|---|
| flux_sockets-0.6.5.tar.gz | 10.9 kB | Without provenance | Details for flux_sockets-0.6.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flux_sockets-0.6.5-py3-none-any.whl | Python 3 | none | any | Details for flux_sockets-0.6.5-py3-none-any.whl |
Total release size: 20.7 kB
Release files / flux_sockets-0.6.5.tar.gz
| Download URL | flux_sockets-0.6.5.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
adf9b4c7eb0e53ab865560822a652a3dfc99bd4fa216c0e90ebcf72041af35e4
|
|
BLAKE2b-256 checksum How to use checksums |
30da133978f478187e78b4ef012531501ffc224f4f8f8486b41511d7c3724fda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / flux_sockets-0.6.5-py3-none-any.whl
| Download URL | flux_sockets-0.6.5-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e3a9d0e6e7104f55154b659d92b98299f4ce19c8a5440d550947d6c222a0c57d
|
|
BLAKE2b-256 checksum How to use checksums |
c23086f1a8d70ffb1b63f5d7dbef521f7b2e6e3babd867f23a0ae985f97af2de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for flux-sockets 0.6.5
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.