A powerful, dependency-injection-driven ASGI web framework for Python with first-class support for configuration management, type-safe routing, and extensible middleware.
Project description
Serving: The Extensible Python Web Framework 🚀
[!WARNING] Serving is currently in alpha and is NOT recommended for production use. APIs are subject to change.
Serving is a small ASGI web framework built on Starlette with first‑class dependency injection (Bevy), YAML configuration, typed routing, forms with CSRF, and themed error pages.
✨ Highlights
- ASGI/Starlette core with a minimal surface area
- Dependency Injection via Bevy (request‑scoped container)
- YAML configuration with typed
ConfigModels (including collections) - Lightweight routing decorator; return‑type‑based responses
- Forms + CSRF with Jinja2 templates
- Themed error pages with dev‑mode details
- Simple CLI wrapper around Uvicorn
- Pluggable sessions with DI‑friendly access
- Static asset mount in dev compatible with
url_for('static', ...)
🚀 Quick Start
Install
pip install getserving[server]
Minimal App
- Router module
# myapp/web.py
from serving.router import Router
from serving.types import PlainText, JSON, Jinja2
from serving.injectors import QueryParam
from serving import redirect
app = Router()
@app.route("/")
async def index() -> Jinja2:
return "home.html", {"message": "Hello from Serving"}
@app.route("/hello")
async def hello(name: QueryParam[str] = "world") -> PlainText:
return f"Hello, {name}!"
@app.route("/redirect")
async def go_home() -> PlainText:
redirect("/")
return "This will not be sent"
- Template
<!-- templates/home.html -->
<h1>{{ message }}</h1>
- Configuration
# serving.dev.yaml
environment: dev
auth:
credential_provider: myapp.auth:MyProvider
config:
csrf_secret: change-me-long-random-string
templates:
directory: templates
static:
mount: /static
directory: static
# In dev, assets are served by default; in other envs default is false.
# Explicitly enable serving in non-dev if desired:
# serve: true
routers:
- entrypoint: myapp.web:app
routes:
- path: "/"
- path: "/hello"
- path: "/redirect"
- Run
serv -e dev --reload
Your app will be available at http://127.0.0.1:8000.
🗝️ Sessions
Serving supports pluggable session providers and a dict‑like Session mapping bound to each request.
Configure a provider in YAML:
# serving.dev.yaml (add alongside `auth`/`routers`)
session:
session_provider: serving.session:InMemorySessionProvider
session_type: serving.session:Session # optional
config: {}
Use the session in routes:
from serving.session import Session
from serving.injectors import SessionParam
@app.route("/whoami")
async def whoami(sess: Session) -> JSON:
return {"user": sess.get("user_id")}
@app.route("/feature")
async def feature(beta: SessionParam[bool] = False) -> JSON:
# Uses parameter name as key; default applies if key is missing
return {"beta": beta}
See the full guide: Sessions
🧭 Return Types
PlainText→ PlainTextResponseJSON→ JSONResponseHTML→ HTMLResponseJinja2→ TemplateResponse (tuple oftemplate_name,context_dict)- Returning a Starlette
Responseis passed through as‑is
🔐 Authentication & Permissions
Configure an auth provider in YAML (auth.credential_provider). Serving calls has_credentials(permissions) before invoking a route; if denied, a themed 401 page is rendered. See Authentication for the CredentialProvider protocol and examples.
🧾 Forms & CSRF
Use serving.forms.Form with Jinja2. When CSRF is enabled (default), templates must call {{ csrf() }}; invalid tokens are rejected by CSRFMiddleware. See Forms & CSRF.
🎨 Error Pages & Theming
Customize error templates via the theming section in YAML. Dev mode can include extra details (stack traces, missing path). See Error Handling & Theming.
🧰 CLI
serv [-d DIR] [-e ENV] [uvicorn options...]
-d, --working-directory DIR— where yourserving.{env}.yamllives-e, --env ENV— choose environment (e.g.,dev,prod)- All other flags are passed to Uvicorn (e.g.,
--reload,--host,--port)
📚 Documentation
See the docs/ directory for detailed guides and references:
- Getting Started — install and minimal setup
- Configuration — YAML layout, templates, theming, routers, auth
- Routing — router decorator, params, permissions
- Dependency Injection — Bevy DI and
ConfigModels - Forms & CSRF — forms + CSRF
- Error Handling — exceptions and theming
- Authentication — provider protocol and configuration
- Middleware — default middleware stack
- Response Helpers —
set_header,redirect, etc. - CLI — CLI flags and examples
- Testing — testing patterns
Also see the demo/blog demo for a runnable example.
🤝 Contributing
Contributions are welcome! Bug reports, feature suggestions, docs, and tests are appreciated. Please open an issue or pull request.
📄 License
MIT — see LICENSE.
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 getserving-0.1.1a7.tar.gz.
File metadata
- Download URL: getserving-0.1.1a7.tar.gz
- Upload date:
- Size: 65.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0f9c75962f395f570f63ac569404124122e25376b8bf5940689f4e4ccbd0bfb
|
|
| MD5 |
9df32039769777264df4e00ae15435f8
|
|
| BLAKE2b-256 |
4576b9809cdc16cc712733911417398546058e53eb0b521b1272fe0bc077a4a7
|
File details
Details for the file getserving-0.1.1a7-py3-none-any.whl.
File metadata
- Download URL: getserving-0.1.1a7-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.6.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93658d607d3c9510560dfdf5836b624e94164c45243d0ff51c15b5a5c62e3316
|
|
| MD5 |
94a7741f66f54337fe424e2e659d729d
|
|
| BLAKE2b-256 |
a65da5724dcb0ee3e072b2a2409dffb4674a94d11c11365133849283d609cabd
|