Skip to main content

WebLib v2 – Minimal ASGI web library MVP per specifiche

Project description

WebLib v2 (MVP)

Una libreria Python minimale (ASGI) che segue le specifiche in specifiche.txt.

Caratteristiche implementate nell’MVP:

  • WebApp con DI minimale, plugin hook, security headers base.
  • Routing con decorators (@route.get, @route.post, ...), path params tipati basilari ({id:int}, {slug}), Routes.register.
  • HTTP helpers (HTTP.ok/created/redirect/html/stream/file).
  • Request/Response ASGI minimi (senza dipendenze esterne).
  • Page/Element/Component immutabili, DSL E.div(...) con escaping HTML, Page.render().
  • CSS scope/merge/minify (no-op) e render compatto.
  • Static assets con mount semplice.
  • Middleware: security_headers, request_id, logging_middleware, cors, rate_limit, sessions (in-memory, dev-only).
  • CLI minimale (weblib new, weblib dev, weblib routes).

Installazione locale:

pip install -e .

Esecuzione esempio minimale:

uvicorn examples.minimal.app:asgi --reload

Esempio Blog con Auth + Postgres:

Requisiti: asyncpg e un Postgres in ascolto su 5432.

pip install asyncpg
export DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
uvicorn examples.blog_auth.app:asgi --reload

Funzionalità:

  • Registrazione e Login/Logout (password PBKDF2, cookie sessione in‑memory)
  • Creazione post di testo (solo utenti autenticati)
  • Lista post come card con autore e timestamp
  • Navigazione tramite menu laterale

Esempio rapido:

from weblib import WebApp
from weblib.routing import Routes, route, HTTP
from weblib.page import Page
from weblib.elements import E
from weblib.css import CSS, css

routes = Routes()

base_css = CSS.scope("base").add(
    css("body", {"font-family": "system-ui"}),
    css(".container", {"max-width": "720px", "margin": "0 auto"}),
)

@route.get("/")
async def home(req):
    return (Page(title="Home").use_css(base_css)
            .body(E.div(E.h1("Hello WebLib"), E.p("It works"), cls="container")))

@route.post("/echo")
async def echo(req):
    data = await req.json()
    return HTTP.created({"you_sent": data})

routes.register(home, echo)
app = WebApp(routes=routes)
asgi = app.asgi
# Avvio (es.): uvicorn myapp:asgi --reload

Note:

  • Questo è un MVP focalizzato sull’API e DX; molti aspetti (ORM, template, WS/SSE, middleware avanzati, sessioni, migrazioni) sono lasciati come stub per iterazioni future.
  • Nessuna dipendenza esterna; performance e sicurezza sono “best-effort” ragionevoli per dev.

Licenza: MIT

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

weblib_py-0.1.10.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

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

weblib_py-0.1.10-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file weblib_py-0.1.10.tar.gz.

File metadata

  • Download URL: weblib_py-0.1.10.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for weblib_py-0.1.10.tar.gz
Algorithm Hash digest
SHA256 04ad6babdff2e27c6da1e4b0abe3286a73e15fe01fcf0595640f1a6681becd31
MD5 f10abd360fc70bad09bae7f2801e2572
BLAKE2b-256 6abe6274802f3bc480f03558615a38ca10aa8ed1e0c21cdc796acbf155ee7d89

See more details on using hashes here.

File details

Details for the file weblib_py-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: weblib_py-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for weblib_py-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 54818872d38c84adbf7569010786bf2867a4607590a7a61e876f06a876357e48
MD5 6c7be4567109e966097d2899dac0888c
BLAKE2b-256 1edd57e835728c30fab48193b6618cd786b5312b4dbc628725e17e0c7a1e68ed

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