Skip to main content

wsbuilder

wsbuilder es una libreria Python 3.11+ para construir servicios HTTP, WebSocket y utilidades de infraestructura en un paquete pequeno, modular y sin dependencias de runtime.

Sirve para crear:

  • APIs JSON y vistas HTML.
  • canales WebSocket.
  • servicios con SQLite embebido y ORM ligero.
  • cache clave-valor y cache HTTP de vistas.
  • rate limiting, ACL, listas de IP y bloqueo temporal.
  • metricas JSON, stream NDJSON, logs y tareas en background.
  • DNS local, mDNS y descubrimiento de servicios, reverse proxy y balanceo.
  • comunicacion entre microservicios en binario (CBOR) sobre HTTP/3 cifrado, con identidad de servicio por mTLS.
  • prediccion simple y redes neuronales basicas desde Python puro.
  • modelos de lenguaje (LLM): motor nativo en Python puro (ByteLanguageModel) para entrenar y generar texto, un unico formato NDJSON para el modelo y sus pesos, almacen con descargas verificadas y API HTTP compatible con OpenAI.

Ruta de documentacion

La documentacion esta organizada por nivel:

  • Principiantes: instala, crea la primera app y entiende rutas view y api.
  • Intermedios: agrega SQLite, cache, seguridad, metricas, logs y tareas.
  • Avanzados: configura limites HTTP, TLS, worker pools, DNS, ProxyI, replicas SQLite y operacion.

Tambien puedes leer:

Instalacion rapida

python -m pip install --upgrade pip
python -m pip install wsbuilder

En Debian, Kali, Ubuntu y otros entornos que aplican PEP 668, pip puede rechazar la instalacion sobre el Python del sistema con externally-managed-environment. Usa un entorno virtual:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install wsbuilder

Verifica:

python -c "import wsbuilder; print(wsbuilder.__version__)"
wsbuilder --help

Inicio rapido

from wsbuilder import App, Response

app = App(cors_allow_origin="*")
app.enable_metrics()
app.enable_docs(path="/docs", json_path="/docs.json")

@app.view("/")
def home(_request):
    return Response.html("<h1>wsbuilder</h1>")

@app.api("/api/health")
def health(_request):
    return {"ok": True}

app.run("127.0.0.1", 8765)

Ejecuta:

python app.py

Abre:

  • http://127.0.0.1:8765/
  • http://127.0.0.1:8765/api/health
  • http://127.0.0.1:8765/docs
  • http://127.0.0.1:8765/api/metrics

Demo incluida

wsbuilder --host 127.0.0.1 --port 8765

La demo incluye:

  • /
  • /monitor
  • /thread-demo
  • /api/health
  • /api/metrics
  • /api/metrics/stream
  • /docs
  • /docs.json
  • /ws/

Mapa de modulos

Area Modulos APIs principales
HTTP app.py, http.py, server.py App, Request, Response, HTTPServer
WebSocket ws.py WebSocket, parse_close_payload, handshake
Datos orm.py, db_replicas.py Database, Model, QuerySet, OptimizedDatabase
Cache cache.py, caches.py SQLiteMemoryCache, ViewResponseCache
Seguridad security.py SecurityPolicy, ACLRule, SecurityDecision
Observabilidad metrics.py, logs.py, tasks.py AppMetrics, NDJSONLog, TaskManager
Red y edge dns.py, mdns.py, proxyi/ LocalDNSServer, LocalMDNSServer, discover_mdns_services, ProxyI
Entre servicios rpc.py, codec.py, http3_client.py App.rpc, RpcClient, RpcError, cbor_dumps, Http3Client
IA y prediccion ia.py, predicts.py DataSet, NeuralNetwork, Predictor
Modelos de lenguaje llm.py, ia_lm.py, ndjson_model.py ByteLanguageModel, ModelStore, LanguageModel, ModelReader, ModelWriter, App.enable_llm

Comunicacion entre servicios

Los servicios se llaman entre si con el payload en CBOR (binario, alrededor de un 30 % mas pequeno que JSON y sin base64 para bytes) sobre una conexion HTTP/3 reutilizada y cifrada con TLS 1.3:

from wsbuilder import App, RpcClient

app = App()

@app.rpc("/users.get")
def get_user(request, payload):
    return {"id": payload["id"], "name": "Ada"}

# En otro servicio:
with RpcClient("https://users.internal:8443", trust=ca) as users:
    user = users.call("/users.get", {"id": 7})

Detalles, mTLS y limites en RPC entre servicios.

Ejemplo con datos

from datetime import UTC, datetime
from wsbuilder import App, Database, DateTimeField, IntegerField, Model, Response, TextField

class Note(Model):
    __tablename__ = "notes"

    id = IntegerField(primary_key=True, auto_increment=True)
    title = TextField(unique=True, null=False, index=True)
    created_at = DateTimeField(default=lambda: datetime.now(UTC), null=False)

app = App(cors_allow_origin="*")
app.db = Database("data/app.sqlite3", enable_wal=True)
Note.create_table(app.db)

@app.api("/api/notes", methods=("GET", "POST"))
def notes(request):
    if request.method == "GET":
        rows = [note.to_dict() for note in Note.objects(app.db).order_by("-id").all()]
        return {"items": rows}

    payload = request.json() or {}
    title = str(payload.get("title", "")).strip()
    if not title:
        return Response.json({"message": "title is required"}, status=400)
    note = Note.create(app.db, title=title)
    return Response.json(note.to_dict(), status=201)

Instalacion local y offline

Desde este repositorio:

python -m pip install .

Instalacion editable para desarrollo:

python -m pip install -e .

Compilar wheel sin red, si ya tienes build, setuptools>=77 y wheel disponibles:

python -m build --no-isolation
python -m pip install --no-index dist/wsbuilder-*.whl

La guia completa esta en Instalacion.

Desarrollo

Comandos utiles del repositorio:

python -m pip install -e .
PYTHONPATH=src pytest -q
python -m build
python -m twine check dist/*
mkdocs build --strict

Estado del proyecto

El paquete esta marcado como Development Status :: 3 - Alpha. Es adecuado para servicios internos, prototipos, demos y laboratorios controlados. Antes de usarlo fuera de localhost, revisa limites de transporte, TLS, seguridad, logs, observabilidad y apagado de recursos.

Contribucion y soporte

  • Crea ramas desde main usando prefijos como feat/, fix/ o docs/.
  • Mantiene cada PR enfocado en un solo cambio logico.
  • Ejecuta las validaciones relevantes antes de abrir PR.
  • Reporta vulnerabilidades de forma privada.

Soporte opcional

Si wsbuilder te resulta util y quieres apoyar el mantenimiento del proyecto, puedes donar en BTC:

bc1q3lhxpr9yantvefmvhpd2h4lu0ykf3t45zvuve2

Red: BTC mainnet (Native SegWit).

Metadata

Release files for wsbuilder 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wsbuilder 2.0.0
File Size Uploaded Provenance Actions
wsbuilder-2.0.0.tar.gz 661.4 kB With provenance Details for wsbuilder-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for wsbuilder 2.0.0
File Interpreter ABI Platform Actions
wsbuilder-2.0.0-py3-none-any.whl Python 3 none any Details for wsbuilder-2.0.0-py3-none-any.whl

Total release size: 1.0 MB

Release files / wsbuilder-2.0.0.tar.gz

Download URL wsbuilder-2.0.0.tar.gz
Size 661.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0b146ee80b42a3d169fdfa6bf6f26a6984af775f8377398c0aedd48bcc54a3a9
BLAKE2b-256 checksum
How to use checksums
931ba6a82d0c16175c084508c192a1daee81c7af1d8e94278fd953eb32b6fe52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Release files / wsbuilder-2.0.0-py3-none-any.whl

Download URL wsbuilder-2.0.0-py3-none-any.whl
Size 366.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
05785f13f07c97d3273d6574eff8f96c6f7ceccd5c28749e83d2a93eff72bec9
BLAKE2b-256 checksum
How to use checksums
7c584344c1fc104b6ae8201cf7e0b49e414d0fee678c0a4df3ea9589b123fb48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

Security for wsbuilder 2.0.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for wsbuilder-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page