Skip to main content

Framework ligero HTTP + WebSocket.

Project description

wsbuilder

wsbuilder es un paquete Python 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.7.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.7-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wsbuilder-0.2.7.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.7.tar.gz
Algorithm Hash digest
SHA256 63554bc2eff9a074e8cf3a3b2cab65706e0ad0e213fe81753dd07db9f710dc37
MD5 9c25026662f56200000391dc1b00807d
BLAKE2b-256 81f118bbc92a0cf40666bc4fbbe323eeb7a091d79082223018722d6a668d00c5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: wsbuilder-0.2.7-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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f6468f34a394ba4e0eab836a6a2a466e046a548dd97a3ecd347933cee00a966e
MD5 d437f593957e93e3d755274d72b198dc
BLAKE2b-256 9687107bacbf05ccf56fe0f83999671281480aa97d50e4224e304e94e299e1e6

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