Skip to main content

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.

Lightweight Python HTTP + WebSocket framework for building real-time APIs and custom servers.

Keywords: python, http-server, websocket, framework, real-time, api, socket.

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)

Para CORS sin variables de entorno:

app = App(cors_allow_origin="*")

HTTP streaming (chunked)

import time
from wsbuilder import App, Response

app = App()

@app.view("/stream")
def stream(_request):
    def chunks():
        for i in range(5):
            yield f"chunk {i}\n"
            time.sleep(1)
    return Response.stream(chunks(), content_type="text/plain; charset=utf-8")

Ejecutar demo incluido

python -m wsbuilder --host 0.0.0.0 --port 8765
# o
wsbuilder --host 0.0.0.0 --port 8765

Configuracion CORS

  • Usa App(cors_allow_origin="https://tu-dominio.com").
  • Usa App(cors_allow_origin="*") para permitir cualquier origen.

CI/CD (GitHub Actions)

  • package-build.yml: construye sdist + wheel, valida metadata y prueba instalacion/import.
  • release-from-main.yml en push a main: calcula semver automaticamente, crea rama release/v<version> desde main, actualiza version del paquete, crea tag v<version> y publica GitHub Release.
  • publish-packages.yml en push de tag v*: construye y publica a PyPI/TestPyPI (instalable con pip).
  • publish-packages.yml en tags v*: adjunta los paquetes al GitHub Release.
  • main-only-from-develop.yml (workflow main-pr-source-check): valida metadata minima del PR hacia main.

Reglas de versionado automatico

  • major: si algun commit trae BREAKING CHANGE, type(scope)!: o ramas/commits marcados como breaking/major.
  • minor: si hay suficiente peso de feat/feature (proporcional frente a cambios patch) y no hay major.
  • patch: cualquier otro caso.

Recomendado usar Conventional Commits para que el calculo de version sea preciso.

Secrets requeridos

  • RELEASE_BOT_TOKEN (recomendado): PAT/fine-grained token para crear rama release/*, crear tag y publicar GitHub Release.
  • RULESET_ADMIN_TOKEN (fallback): usado automaticamente si no existe RELEASE_BOT_TOKEN.
  • PYPI_API_TOKEN: token de publicacion para PyPI.
  • TEST_PYPI_API_TOKEN (opcional): token de publicacion para TestPyPI.

Project details


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.2.5.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wsbuilder-0.2.5-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file wsbuilder-0.2.5.tar.gz.

File metadata

  • Download URL: wsbuilder-0.2.5.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for wsbuilder-0.2.5.tar.gz
Algorithm Hash digest
SHA256 5cb8059bff65a8ed6ac3e587305d6adb88afa6029cb57af9d2b94f8175d782d2
MD5 3bfdafcacfe42f17e473462efff842b0
BLAKE2b-256 d3d5247de48aee77505c3ac625175f74c040dccbf58a5ea0d65c941b4572c194

See more details on using hashes here.

File details

Details for the file wsbuilder-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: wsbuilder-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for wsbuilder-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7759e581052bd916e88dc17c6904bc592ebf8a6d66e0c6e3bf9dcb2f2e88a587
MD5 4a3bc4d98eb27aefcc4ea1bfdfcd90a1
BLAKE2b-256 2ddd80a7ad484ddff9876be5212364de03169bfaf8bd2a4879bfb780779dfef5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page