Framework ligero HTTP + WebSocket extraido de PortHound4.
Project description
wsbuilder
wsbuilder es un paquete Python extraido de PortHound4 para construir servidores HTTP + WebSocket sin dependencias externas.
Incluye
wsbuilder.framework: router, request/response, servidor HTTP, handshake WS y utilidades de frames.wsbuilder.ws_demo: demo completo HTTP + WebSocket + REST + SQLite.
Instalacion local
python -m pip install -e .
Uso rapido del framework
from wsbuilder import App, Response, parse_close_payload
app = App()
@app.view("/")
def home(_request):
return Response.html("<h1>wsbuilder</h1>")
@app.api("/api/health")
def health(_request):
return {"ok": True}
@app.ws("/ws/")
def ws_handler(ws, _request):
while True:
fin, opcode, payload, _masked, _mask = ws.recv_frame()
if opcode == 0x8:
code, reason = parse_close_payload(payload)
ws.close(code or 1000, reason or "")
break
if opcode == 0x9:
ws.send_pong(payload)
continue
if opcode == 0x1:
ws.send_text(payload.decode("utf-8", errors="ignore"))
elif opcode == 0x2:
ws.send_binary(payload)
app.run("0.0.0.0", 8765)
Ejecutar demo incluido
python -m wsbuilder --host 0.0.0.0 --port 8765
# o
wsbuilder --host 0.0.0.0 --port 8765
Variables de entorno
WSBUILDER_CORS_ALLOW_ORIGIN: valor CORS para rutas@app.api.- Compatibilidad heredada: tambien respeta
PORTHOUND_CORS_ALLOW_ORIGIN.
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
wsbuilder-0.1.0.tar.gz
(24.0 kB
view details)
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
wsbuilder-0.1.0-py3-none-any.whl
(25.8 kB
view details)
File details
Details for the file wsbuilder-0.1.0.tar.gz.
File metadata
- Download URL: wsbuilder-0.1.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ddb1fcb7c35091fb17dcd5c91d3c5ba0d8f2e866a097ebe48142815f3e990ae0
|
|
| MD5 |
6440daeb704bb4fc890cbd0a5055fc1c
|
|
| BLAKE2b-256 |
c15e5054248e7f680dcc65844052b18ac3daf1ae65a4b9f8e2818f08360012b3
|
File details
Details for the file wsbuilder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: wsbuilder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8aee3c77e9d705987786442de9df298c60a5e7a6ba22b4d05d729ad1741deff
|
|
| MD5 |
8fe4824c2ed853b14bb7fb9409604f59
|
|
| BLAKE2b-256 |
e5f8298754ddae5f7280829eff00800e99c3b35e3302ee3ffff6ef2b865a9582
|