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). - ORM: adapter
SQLiteORMminimale confieldsdichiarativi e CRUD base.
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; template, WS/SSE, plugin avanzati e migrazioni evolute sono previsti in future iterazioni.
- Nessuna dipendenza esterna per l’ORM incluso (usa
sqlite3standard via threadpool). Performance e sicurezza sono “best-effort” per dev.
Licenza: MIT
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
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
File details
Details for the file weblib_py-0.1.13.tar.gz.
File metadata
- Download URL: weblib_py-0.1.13.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a591ee059713b8f1541d6d7749ce3a6a89b6a9f6e5f407151139f3b88cf2df0e
|
|
| MD5 |
43f875e2a9491e7e4a545b96e27a22d7
|
|
| BLAKE2b-256 |
d245b782f3c3d601487218ccf34d13918a22aa46e040efd680bcf4247171ef7a
|
File details
Details for the file weblib_py-0.1.13-py3-none-any.whl.
File metadata
- Download URL: weblib_py-0.1.13-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d750b32195e8cfc494cafe6f7f3bf4304de1db293bbb7f2d91852318087a9021
|
|
| MD5 |
89bdb4834a5c52adf756673bc6883e9c
|
|
| BLAKE2b-256 |
bc078d046c295209dc26e01d21f2c65b172c7d46265ad990ee273187861fdc3d
|