spiderweb-framework 2.2.1__tar.gz → 2.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spiderweb_framework-2.4.0/.github/workflows/publish.yml +23 -0
- spiderweb_framework-2.4.0/.github/workflows/retype.yml +26 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.junie/guidelines.md +20 -9
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/PKG-INFO +5 -1
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/README.md +2 -3
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_sidebar.md +2 -0
- spiderweb_framework-2.4.0/docs/asgi.md +173 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/file_uploads.md +1 -1
- spiderweb_framework-2.4.0/docs/management.md +311 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/custom_middleware.md +1 -1
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/gzip.md +1 -1
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/routes.md +140 -2
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/static_files.md +2 -2
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/example.py +1 -1
- spiderweb_framework-2.4.0/example_async.py +269 -0
- spiderweb_framework-2.4.0/example_async_middleware.py +82 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/pyproject.toml +13 -1
- spiderweb_framework-2.4.0/retype.yml +19 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/__init__.py +2 -0
- spiderweb_framework-2.4.0/spiderweb/asgi.py +258 -0
- spiderweb_framework-2.4.0/spiderweb/cli.py +636 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/local_server.py +33 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/main.py +50 -4
- spiderweb_framework-2.4.0/spiderweb/middleware/__init__.py +185 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/middleware/pydantic.py +6 -3
- spiderweb_framework-2.4.0/spiderweb/routegroup.py +44 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/routes.py +72 -14
- spiderweb_framework-2.4.0/spiderweb/tests/test_asgi.py +191 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_asgi_extra.py +381 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_cli.py +671 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_coverage_extras.py +216 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_local_server_extra.py +154 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_main_extra.py +336 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_middleware_init.py +245 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_pydantic_middleware.py +185 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_routegroups.py +391 -0
- spiderweb_framework-2.4.0/spiderweb/tests/test_utils.py +288 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/uv.lock +99 -2
- spiderweb_framework-2.2.1/.idea/workspace.xml +0 -278
- spiderweb_framework-2.2.1/spiderweb/middleware/__init__.py +0 -77
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.gitignore +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/.gitignore +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/inspectionProfiles/Project_Default.xml +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/inspectionProfiles/profiles_settings.xml +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/misc.xml +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/modules.xml +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/spiderweb.iml +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/.idea/vcs.xml +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/LICENSE.txt +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/Makefile +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/README.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/conftest.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/.nojekyll +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_coverpage.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/DMSans-Bold.ttf +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/DMSans-Medium.ttf +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/Favicon-32x32.png +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/favicon.png +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/spiderweb_logo.png +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/spiderweb_logo_cleaned.png +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/_media/spiderweb_logo_cropped.png +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/db.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/example.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/index.html +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/cors.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/csrf.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/overview.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/pydantic.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/sessions.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/quickstart.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/responses.md +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/example2.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/example_middleware.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/constants.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/converters.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/db.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/decorators.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/default_views.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/example_validator.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/exceptions.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/files.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/jinja_core.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/jinja_extensions.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/middleware/base.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/middleware/cors.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/middleware/csrf.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/middleware/gzip.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/middleware/sessions.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/request.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/response.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/secrets.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/server_checks.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/__init__.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/helpers.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/middleware.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/staticfiles/.gitkeep +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/staticfiles/file_for_testing_fileresponse.txt +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/staticfiles/style.css +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test.html +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_cookies.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_db.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_exceptions.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_files.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_jinja_extras.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_local_server.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_middleware.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_responses.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_secrets.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_server.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_server_checks.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/test_variable_urls.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/tests/views_for_tests.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/spiderweb/utils.py +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/static_files/aaaaaa.gif +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/templates/base.html +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/templates/file_upload.html +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/templates/form.html +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/templates/test.html +0 -0
- {spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/tools/update_version.py +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
name: Build and publish to PyPI
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v6
|
|
14
|
+
|
|
15
|
+
- uses: astral-sh/setup-uv@v8.0.0
|
|
16
|
+
|
|
17
|
+
- name: Build package
|
|
18
|
+
run: uv build
|
|
19
|
+
|
|
20
|
+
- name: Publish to PyPI
|
|
21
|
+
run: uv publish
|
|
22
|
+
env:
|
|
23
|
+
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
name: Publish Retype powered website to GitHub Pages
|
|
2
|
+
on:
|
|
3
|
+
workflow_dispatch:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
name: Publish to retype branch
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: write
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v6
|
|
19
|
+
|
|
20
|
+
- uses: retypeapp/action-build@latest
|
|
21
|
+
with:
|
|
22
|
+
key: ${{ secrets.RETYPE_PASSWORD }}
|
|
23
|
+
|
|
24
|
+
- uses: retypeapp/action-github-pages@latest
|
|
25
|
+
with:
|
|
26
|
+
update-branch: true
|
|
@@ -4,17 +4,18 @@ Spiderweb framework — Development Guidelines
|
|
|
4
4
|
Spiderweb is a minimalist Python web framework that blends Django- and Flask-like patterns. It provides function-based views, routing (Flask-style and Django-style, with variable converters), middleware, templating (Jinja2), static files, cookies, sessions, CSRF and CORS middleware, optional Pydantic validation, and a simple built-in WSGI dev server. The codebase targets Python 3.11–3.13.
|
|
5
5
|
|
|
6
6
|
1) Build/Configuration Instructions
|
|
7
|
-
- Supported Python: 3.11–3.13 (see pyproject.toml). The library itself has minimal runtime deps (
|
|
7
|
+
- Supported Python: 3.11–3.13 (see pyproject.toml). The library itself has minimal runtime deps (sqlalchemy, jinja2, cryptography, email-validator, pydantic). Dev tooling uses pytest, hypothesis, coverage, ruff, black.
|
|
8
8
|
- Dependency management:
|
|
9
|
-
- With
|
|
10
|
-
- Install:
|
|
11
|
-
- Run commands:
|
|
12
|
-
- Without
|
|
9
|
+
- With uv (recommended):
|
|
10
|
+
- Install: uv sync
|
|
11
|
+
- Run commands: uv run python -m spiderweb (if you expose an entry point) or uv run python example.py
|
|
12
|
+
- Without uv:
|
|
13
13
|
- Create venv and install: python -m venv .venv && .venv\Scripts\activate (Windows) or source .venv/bin/activate (POSIX); then pip install -e .[dev]
|
|
14
14
|
Note: If extras aren’t configured, pip install -e . and then pip install the dev tools you need (pytest, coverage, black, ruff).
|
|
15
15
|
|
|
16
16
|
- Running an example app:
|
|
17
17
|
- Minimal app:
|
|
18
|
+
```
|
|
18
19
|
from spiderweb import SpiderwebRouter
|
|
19
20
|
from spiderweb.response import HttpResponse
|
|
20
21
|
|
|
@@ -26,6 +27,7 @@ Spiderweb is a minimalist Python web framework that blends Django- and Flask-lik
|
|
|
26
27
|
|
|
27
28
|
if __name__ == "__main__":
|
|
28
29
|
app.start()
|
|
30
|
+
```
|
|
29
31
|
- Alternatively, run the provided examples: python example.py or python example2.py.
|
|
30
32
|
|
|
31
33
|
- Configuration surface (high-signal items; see SpiderwebRouter.__init__ in spiderweb/main.py):
|
|
@@ -35,7 +37,7 @@ Spiderweb is a minimalist Python web framework that blends Django- and Flask-lik
|
|
|
35
37
|
- allowed_hosts: List or regex patterns for host checking.
|
|
36
38
|
- CORS: cors_* options mirror standard CORS settings, with sane defaults (see constants.py and main.py for defaults and behavior).
|
|
37
39
|
- Sessions/CSRF: session_* options define cookie properties and expiry; CSRF relies on session middleware (ordering matters; see below).
|
|
38
|
-
- DB: pass a
|
|
40
|
+
- DB: pass a SQLAlchemy Engine, a database URL string, or a filesystem path for SQLite (defaults to `spiderweb-tests.db` during tests via `helpers.setup()`).
|
|
39
41
|
|
|
40
42
|
2) Testing Information
|
|
41
43
|
- Test runner: pytest (configured in pyproject.toml; addopts sets --maxfail=2 -rf).
|
|
@@ -53,7 +55,7 @@ Spiderweb is a minimalist Python web framework that blends Django- and Flask-lik
|
|
|
53
55
|
- Project-specific fixtures/helpers:
|
|
54
56
|
- conftest.py defines a session-scoped autouse fixture that deletes spiderweb-tests.db before and after the test session. Do not rely on persistent data between tests.
|
|
55
57
|
- spiderweb.tests.helpers.setup() returns (app, environ, start_response):
|
|
56
|
-
- app is a SpiderwebRouter with a default
|
|
58
|
+
- app is a SpiderwebRouter with a default SQLite database ("spiderweb-tests.db").
|
|
57
59
|
- environ is a WSGI environ seeded via wsgiref.util.setup_testing_defaults.
|
|
58
60
|
- start_response is a helper capturing status and headers.
|
|
59
61
|
- Use this to simulate WSGI calls without a real server.
|
|
@@ -64,6 +66,7 @@ Spiderweb is a minimalist Python web framework that blends Django- and Flask-lik
|
|
|
64
66
|
- Prefer black/ruff-compliant style; avoid side effects that depend on execution order.
|
|
65
67
|
- For routes, define them on a local SpiderwebRouter instance inside the test to avoid cross-test pollution.
|
|
66
68
|
- Example pattern:
|
|
69
|
+
```
|
|
67
70
|
from spiderweb.response import HttpResponse
|
|
68
71
|
from spiderweb.tests.helpers import setup
|
|
69
72
|
|
|
@@ -80,7 +83,7 @@ Spiderweb is a minimalist Python web framework that blends Django- and Flask-lik
|
|
|
80
83
|
body_iter = app(environ, start_response)
|
|
81
84
|
assert start_response.status.startswith("200")
|
|
82
85
|
assert b"".join(body_iter) == b"pong"
|
|
83
|
-
|
|
86
|
+
```
|
|
84
87
|
- Demo test flow (validated during guideline creation):
|
|
85
88
|
- A temporary test using helpers.setup() and a trivial route was created, executed with python -m pytest -k minimal_route_responds_200 (1 test passed), then removed. This demonstrates the idiomatic testing flow for this codebase.
|
|
86
89
|
|
|
@@ -105,7 +108,15 @@ Spiderweb is a minimalist Python web framework that blends Django- and Flask-lik
|
|
|
105
108
|
- FileResponse sets content-type via mimetypes and streams body as bytes via wsgiref FileWrapper.
|
|
106
109
|
|
|
107
110
|
- Database:
|
|
108
|
-
-
|
|
111
|
+
- Spiderweb uses Advanced Alchemy (built on SQLAlchemy) for internals like sessions.
|
|
112
|
+
- Pass a database URL, SQLAlchemy Engine, or path to `SpiderwebRouter(db=...)`.
|
|
113
|
+
- User models should inherit from `spiderweb.db.Base`.
|
|
114
|
+
- In tests, a throwaway SQLite DB is used via `helpers.setup()`.
|
|
115
|
+
|
|
116
|
+
- Migrations:
|
|
117
|
+
- Spiderweb works with Alembic for database migrations.
|
|
118
|
+
- To use, initialize Alembic (`alembic init migrations`) and set `target_metadata = Base.metadata` in `migrations/env.py` (import `Base` from `spiderweb.db`).
|
|
119
|
+
- Generate migrations with `alembic revision --autogenerate` and apply with `alembic upgrade head`.
|
|
109
120
|
|
|
110
121
|
- Debugging tips:
|
|
111
122
|
- Use the StartResponse helper to inspect status and headers easily: dict(start_response.get_headers()).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: spiderweb-framework
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.4.0
|
|
4
4
|
Summary: A small web framework, just big enough for a spider.
|
|
5
5
|
Project-URL: Homepage, https://github.com/itsthejoker/spiderweb
|
|
6
6
|
Project-URL: Documentation, https://github.com/itsthejoker/spiderweb
|
|
@@ -22,11 +22,15 @@ Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
|
|
|
22
22
|
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
23
23
|
Requires-Python: >=3.11
|
|
24
24
|
Requires-Dist: advanced-alchemy<2.0.0,>=1.6.3
|
|
25
|
+
Requires-Dist: alembic>=1.17.0
|
|
25
26
|
Requires-Dist: cryptography>=46.0.2
|
|
26
27
|
Requires-Dist: email-validator>=2.3.0
|
|
27
28
|
Requires-Dist: jinja2>=3.1.6
|
|
28
29
|
Requires-Dist: multipart>=1.3.0
|
|
29
30
|
Requires-Dist: sqlalchemy>=2.0.44
|
|
31
|
+
Requires-Dist: uvicorn>=0.44.0
|
|
32
|
+
Provides-Extra: asgi
|
|
33
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'asgi'
|
|
30
34
|
Provides-Extra: pydantic
|
|
31
35
|
Requires-Dist: pydantic<3,>=2.8.2; extra == 'pydantic'
|
|
32
36
|
Description-Content-Type: text/markdown
|
|
@@ -94,10 +94,9 @@ Spiderweb takes a middle ground approach: it allows you to declare framework-fir
|
|
|
94
94
|
|
|
95
95
|
```python
|
|
96
96
|
from spiderweb import SpiderwebRouter
|
|
97
|
-
from peewee import SqliteDatabase
|
|
98
97
|
|
|
99
98
|
app = SpiderwebRouter(
|
|
100
|
-
db=
|
|
99
|
+
db="myapp.db",
|
|
101
100
|
port=4500,
|
|
102
101
|
session_cookie_name="myappsession",
|
|
103
102
|
my_middleware_data="Test!"
|
|
@@ -127,7 +126,7 @@ Here's a non-exhaustive list of things this can do:
|
|
|
127
126
|
- CORS middleware
|
|
128
127
|
- Optional POST data validation middleware with Pydantic
|
|
129
128
|
- Session middleware with built-in session store
|
|
130
|
-
- Database support (using
|
|
129
|
+
- Database support (using SQLAlchemy, but you can use whatever you want as long as there's a SQLAlchemy driver for it)
|
|
131
130
|
- Tests (currently a little over 80% coverage)
|
|
132
131
|
|
|
133
132
|
[^1]: I mostly succeeded. The way that I'm approaching this is that I did my level best, then looked at (and copied) existing solutions where necessary. At the time of this writing, I did all of it solo except for the CORS middleware. [Read more about it here.](middleware/cors.md)
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# asgi
|
|
2
|
+
|
|
3
|
+
[!badge New in 2.3.0!]
|
|
4
|
+
|
|
5
|
+
Spiderweb supports both WSGI and ASGI from the same `SpiderwebRouter` instance. Your existing WSGI app continues to work exactly as before; ASGI is strictly opt-in.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
ASGI mode requires `uvicorn`, which is available as an optional extra:
|
|
10
|
+
|
|
11
|
+
<!-- tabs:start -->
|
|
12
|
+
|
|
13
|
+
<!-- tab:uv -->
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
uv add "spiderweb-framework[asgi]"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
<!-- tab:pip -->
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
pip install "spiderweb-framework[asgi]"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
<!-- tab:pipenv -->
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
pipenv install "spiderweb-framework[asgi]"
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
<!-- tabs:end -->
|
|
32
|
+
|
|
33
|
+
## The Dev Server
|
|
34
|
+
|
|
35
|
+
The simplest way to run your app in ASGI mode during development is `app.start_asgi()`. It behaves just like `app.start()`, but runs through uvicorn instead of `wsgiref`.
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from spiderweb import SpiderwebRouter
|
|
39
|
+
from spiderweb.response import HttpResponse
|
|
40
|
+
|
|
41
|
+
app = SpiderwebRouter()
|
|
42
|
+
|
|
43
|
+
@app.route("/")
|
|
44
|
+
def index(request):
|
|
45
|
+
return HttpResponse("Hello from ASGI!")
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
app.start_asgi()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
> [!WARNING]
|
|
52
|
+
> The dev server is just that: for development. Do not use for production.
|
|
53
|
+
|
|
54
|
+
## Production Deployment
|
|
55
|
+
|
|
56
|
+
For production, pass `app.asgi_app` to any ASGI-compatible server. The `asgi_app` property returns the same `ASGIHandler` instance every time, so it's safe to pass once and reuse.
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
uvicorn myapp:app.asgi_app --workers 4
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Or with Hypercorn:
|
|
63
|
+
|
|
64
|
+
```shell
|
|
65
|
+
hypercorn myapp:app.asgi_app
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Async Views
|
|
69
|
+
|
|
70
|
+
Views can be defined as `async def` and they will be awaited natively in ASGI mode. Sync views continue to work too — they're dispatched via `asyncio.to_thread` so they don't block the event loop.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
@app.route("/sync")
|
|
74
|
+
def sync_view(request):
|
|
75
|
+
return HttpResponse("I'm sync")
|
|
76
|
+
|
|
77
|
+
@app.route("/async")
|
|
78
|
+
async def async_view(request):
|
|
79
|
+
return HttpResponse("I'm async")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Both of the above work under both WSGI and ASGI. There's no need to pick one or the other.
|
|
83
|
+
|
|
84
|
+
## Lifespan Callbacks
|
|
85
|
+
|
|
86
|
+
You can register startup and shutdown callbacks when creating the router. These are called by the ASGI server during the lifespan protocol — startup before the first request, shutdown after the last.
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
def on_start():
|
|
90
|
+
print("server is ready")
|
|
91
|
+
|
|
92
|
+
async def on_stop():
|
|
93
|
+
print("server is shutting down")
|
|
94
|
+
|
|
95
|
+
app = SpiderwebRouter(
|
|
96
|
+
on_startup=[on_start],
|
|
97
|
+
on_shutdown=[on_stop],
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Both sync and async callbacks are supported. They're no-ops when running under WSGI.
|
|
102
|
+
|
|
103
|
+
## Async Middleware
|
|
104
|
+
|
|
105
|
+
Middleware can define `async def` versions of `process_request`, `process_response`, and `post_process`. Spiderweb detects them and awaits them in ASGI mode. Sync middleware works in both modes via `asyncio.to_thread`.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from spiderweb.middleware import SpiderwebMiddleware
|
|
109
|
+
from spiderweb.request import Request
|
|
110
|
+
from spiderweb.response import HttpResponse
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class TimingMiddleware(SpiderwebMiddleware):
|
|
114
|
+
async def process_request(self, request: Request) -> None:
|
|
115
|
+
import time
|
|
116
|
+
request.start_time = time.monotonic()
|
|
117
|
+
|
|
118
|
+
async def process_response(self, request: Request, response: HttpResponse) -> None:
|
|
119
|
+
if hasattr(request, "start_time"):
|
|
120
|
+
import time
|
|
121
|
+
elapsed = time.monotonic() - request.start_time
|
|
122
|
+
response.headers["X-Request-Time"] = f"{elapsed:.4f}s"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
> [!NOTE]
|
|
126
|
+
> You only need to define the hooks you actually use. Middleware that only defines `process_request` doesn't need `process_response`, and vice versa.
|
|
127
|
+
|
|
128
|
+
> See [writing your own middleware](middleware/custom_middleware.md) for the full middleware API.
|
|
129
|
+
|
|
130
|
+
## Request Body Size Limit
|
|
131
|
+
|
|
132
|
+
By default, Spiderweb rejects request bodies larger than **10 MB** with a `413` response. You can raise or remove the limit when creating the router:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
app = SpiderwebRouter(
|
|
136
|
+
max_request_body_size=50 * 1024 * 1024, # 50 MB
|
|
137
|
+
)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Pass `None` to disable the limit entirely:
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
app = SpiderwebRouter(
|
|
144
|
+
max_request_body_size=None, # no limit
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
> [!WARNING]
|
|
149
|
+
> Disabling the size limit means a single request can exhaust your server's memory. Only do this if you have another mechanism (e.g. a reverse proxy) enforcing a limit upstream.
|
|
150
|
+
|
|
151
|
+
## WSGI and ASGI Side by Side
|
|
152
|
+
|
|
153
|
+
You can use both protocols at the same time from the same `SpiderwebRouter` instance. The WSGI `__call__` is untouched; `asgi_app` is a separate entry point.
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
app = SpiderwebRouter()
|
|
157
|
+
|
|
158
|
+
# WSGI — pass to gunicorn, wsgiref, etc.
|
|
159
|
+
wsgi_app = app
|
|
160
|
+
|
|
161
|
+
# ASGI — pass to uvicorn, hypercorn, etc.
|
|
162
|
+
asgi_app = app.asgi_app
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Configuration Reference
|
|
166
|
+
|
|
167
|
+
These `SpiderwebRouter` parameters are specific to ASGI support:
|
|
168
|
+
|
|
169
|
+
| Parameter | Type | Default | Description |
|
|
170
|
+
|---|---|---|---|
|
|
171
|
+
| `on_startup` | `list[Callable]` | `[]` | Callbacks invoked during ASGI lifespan startup. |
|
|
172
|
+
| `on_shutdown` | `list[Callable]` | `[]` | Callbacks invoked during ASGI lifespan shutdown. |
|
|
173
|
+
| `max_request_body_size` | `int \| None` | `10 * 1024 * 1024` | Maximum request body in bytes. `None` disables the limit. |
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# handling file uploads
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[!badge New in 2.2.0!]
|
|
4
4
|
|
|
5
5
|
Spiderweb supports handling file uploads via standard HTML forms that use multipart/form-data. Uploaded files are parsed into Request.FILES as a MultiDict of MediaFile objects, which provide convenient helpers like filename, content_type, size, read(), seek(), and save().
|
|
6
6
|
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
# management
|
|
2
|
+
|
|
3
|
+
[!badge New in 2.4.0!]
|
|
4
|
+
|
|
5
|
+
Spiderweb ships with a built-in management CLI — a single command you can use to start the dev server, explore your routes, open an interactive shell, and run startup checks. If you've ever used Django's `manage.py`, this will feel familiar.
|
|
6
|
+
|
|
7
|
+
After installing the package, the `web` command is available in your environment:
|
|
8
|
+
|
|
9
|
+
```shell
|
|
10
|
+
web --help
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## pointing the CLI at your app
|
|
14
|
+
|
|
15
|
+
All commands (except `version`) need to know which `SpiderwebRouter` instance to work with. There are three ways to tell them, in order of priority:
|
|
16
|
+
|
|
17
|
+
**1. The `--app` flag**
|
|
18
|
+
|
|
19
|
+
Pass the app location directly on the command line as `module:attribute`:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
web --app myapp:app serve
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
**2. The `SPIDERWEB_APP` environment variable**
|
|
26
|
+
|
|
27
|
+
This is helpful for CI pipelines of for folks who like to have everything set in the shell.
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
export SPIDERWEB_APP=myapp:app
|
|
31
|
+
web serve
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**3. `pyproject.toml`**
|
|
35
|
+
|
|
36
|
+
Add a `[tool.spiderweb]` section to your project's `pyproject.toml`. The CLI walks up from your current directory until it finds one:
|
|
37
|
+
|
|
38
|
+
```toml
|
|
39
|
+
[tool.spiderweb]
|
|
40
|
+
app = "myapp:app"
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
With that in place you can use any command bare, with no flags at all:
|
|
44
|
+
|
|
45
|
+
```shell
|
|
46
|
+
web serve
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> [!TIP]
|
|
50
|
+
> The `pyproject.toml` approach is the most ergonomic for day-to-day development. Set it once and forget about it.
|
|
51
|
+
|
|
52
|
+
## commands
|
|
53
|
+
|
|
54
|
+
### version
|
|
55
|
+
|
|
56
|
+
Prints the installed version of `spiderweb`. This is the one command that doesn't need an app.
|
|
57
|
+
|
|
58
|
+
```shell
|
|
59
|
+
$ web version
|
|
60
|
+
spiderweb-framework 2.4.0
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### serve
|
|
64
|
+
|
|
65
|
+
Starts the development server. By default it runs in WSGI mode on whatever address and port your app was configured with (`localhost:8000` unless you changed them).
|
|
66
|
+
|
|
67
|
+
```shell
|
|
68
|
+
web serve
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Switch to ASGI mode with `--asgi`:
|
|
72
|
+
|
|
73
|
+
```shell
|
|
74
|
+
web serve --asgi
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Override the bind address or port without touching your source code:
|
|
78
|
+
|
|
79
|
+
```shell
|
|
80
|
+
web serve --addr 0.0.0.0 --port 9000
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
If your project always runs in ASGI mode, set `asgi = true` in `[tool.spiderweb]`:
|
|
84
|
+
|
|
85
|
+
```toml
|
|
86
|
+
[tool.spiderweb]
|
|
87
|
+
app = "myapp:app"
|
|
88
|
+
asgi = true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
You can still override it on the command line in either direction — `--asgi` forces ASGI, `--wsgi` forces WSGI regardless of what `pyproject.toml` says.
|
|
92
|
+
|
|
93
|
+
> [!WARNING]
|
|
94
|
+
> The dev server is just that: for development. Do not use for production.
|
|
95
|
+
|
|
96
|
+
### shell
|
|
97
|
+
|
|
98
|
+
Opens an interactive Python interpreter with your app already loaded as `app`. Great for poking around at runtime state, testing a database query, or trying out a piece of logic before committing it.
|
|
99
|
+
|
|
100
|
+
```shell
|
|
101
|
+
$ spiderweb shell
|
|
102
|
+
Spiderweb 2.4.0 shell
|
|
103
|
+
Available names: app
|
|
104
|
+
Type "exit()" or Ctrl-D to quit.
|
|
105
|
+
|
|
106
|
+
>>> app.addr
|
|
107
|
+
'localhost'
|
|
108
|
+
>>> with app.get_db_session() as session:
|
|
109
|
+
... # query away
|
|
110
|
+
... pass
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
If [IPython](https://ipython.org/) is installed in your environment, the shell will use it automatically. Otherwise, it falls back to the standard library `code.interact`.
|
|
114
|
+
|
|
115
|
+
### routes
|
|
116
|
+
|
|
117
|
+
Prints a table of every URL route your app has registered — path, allowed methods, optional name, and the view function.
|
|
118
|
+
|
|
119
|
+
```shell
|
|
120
|
+
$ spiderweb routes
|
|
121
|
+
path methods name view
|
|
122
|
+
-----------------------------------------------------------------------
|
|
123
|
+
/ POST, GET, PUT, PATCH, DELETE index
|
|
124
|
+
/about POST, GET, PUT, PATCH, DELETE about
|
|
125
|
+
/posts/{slug} POST, GET, PUT, PATCH, DELETE posts get_post
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Routes that haven't restricted their methods show the full default set. If you pass `allowed_methods=["GET"]` to `@app.route()`, only that method appears in the table. Handy for double-checking that a new route was picked up correctly, or for tracking down a duplicate.
|
|
129
|
+
|
|
130
|
+
### check
|
|
131
|
+
|
|
132
|
+
Re-runs all middleware startup checks and tells you whether everything looks healthy.
|
|
133
|
+
|
|
134
|
+
```shell
|
|
135
|
+
$ web check
|
|
136
|
+
System check passed.
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
If any check fails, a `StartupErrors` exception group is raised — you'll see a one-frame traceback listing every failing check. Useful in CI or as a quick sanity check after a config change.
|
|
140
|
+
|
|
141
|
+
### makemigrations
|
|
142
|
+
|
|
143
|
+
Generates a new Alembic migration by comparing your current models against the database schema.
|
|
144
|
+
|
|
145
|
+
```shell
|
|
146
|
+
web makemigrations
|
|
147
|
+
web makemigrations -m "add users table"
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
The first time you run this command the CLI scaffolds a `migrations/` directory next to your `pyproject.toml` (or in the current directory if no `pyproject.toml` is found):
|
|
151
|
+
|
|
152
|
+
```
|
|
153
|
+
migrations/
|
|
154
|
+
env.py ← configure your model metadata here
|
|
155
|
+
script.py.mako ← template for generated migration files
|
|
156
|
+
versions/ ← individual migration scripts live here
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
By default, Alembic compares spiderweb's own internal tables against the live database. To include your own models, open `migrations/env.py` and add your `Base` to `target_metadata`:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from myapp.models import Base as _AppBase
|
|
163
|
+
|
|
164
|
+
target_metadata = [_SpiderwebBase.metadata, _AppBase.metadata]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Options**
|
|
168
|
+
|
|
169
|
+
| Flag | Description |
|
|
170
|
+
|---|---|
|
|
171
|
+
| `-m MESSAGE` / `--message MESSAGE` | Short description embedded in the migration filename. |
|
|
172
|
+
| `--empty` | Create a blank migration without running autogenerate. Useful for hand-written data migrations. |
|
|
173
|
+
|
|
174
|
+
### migrate
|
|
175
|
+
|
|
176
|
+
Applies pending migrations to the database. Without arguments it upgrades to the latest revision (`head`).
|
|
177
|
+
|
|
178
|
+
```shell
|
|
179
|
+
web migrate
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Pass a specific revision ID, a relative step, or the special value `zero` to target a particular point in the migration history:
|
|
183
|
+
|
|
184
|
+
```shell
|
|
185
|
+
web migrate abc123de # upgrade (or already at this rev: no-op)
|
|
186
|
+
web migrate +1 # apply the next pending migration
|
|
187
|
+
web migrate -1 # roll back the most recent migration
|
|
188
|
+
web migrate zero # roll back every migration (equivalent to `base`)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Options**
|
|
192
|
+
|
|
193
|
+
| Flag | Description |
|
|
194
|
+
|---|---|
|
|
195
|
+
| `REVISION` | Target revision (default: `head`). |
|
|
196
|
+
| `--fake` | Stamp the database at the target revision without executing any SQL — useful for marking existing schemas as migrated. |
|
|
197
|
+
|
|
198
|
+
> [!TIP]
|
|
199
|
+
> You can configure where the migrations directory lives by setting `migrations_dir` in `[tool.spiderweb]`:
|
|
200
|
+
>
|
|
201
|
+
> ```toml
|
|
202
|
+
> [tool.spiderweb]
|
|
203
|
+
> app = "myapp:app"
|
|
204
|
+
> migrations_dir = "db/migrations"
|
|
205
|
+
> ```
|
|
206
|
+
|
|
207
|
+
## custom commands
|
|
208
|
+
|
|
209
|
+
You can register your own management commands on the router using the `@app.command()` decorator. Every custom command receives three arguments:
|
|
210
|
+
|
|
211
|
+
- `app` — the `SpiderwebRouter` instance, so you can access the database, routes, config, etc.
|
|
212
|
+
- `args` — an `argparse.Namespace` containing only `.app` and `.command` (the values the CLI's own pre-parser resolved). It does **not** contain any flags you pass after the command name.
|
|
213
|
+
- `extra` — a plain `list[str]` of every token that appeared after the command name on the command line. Parse this yourself if your command accepts flags.
|
|
214
|
+
|
|
215
|
+
A command with no extra flags:
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from spiderweb import SpiderwebRouter
|
|
219
|
+
from spiderweb.response import HttpResponse
|
|
220
|
+
|
|
221
|
+
app = SpiderwebRouter()
|
|
222
|
+
|
|
223
|
+
@app.route("/")
|
|
224
|
+
def index(request):
|
|
225
|
+
return HttpResponse("hello!")
|
|
226
|
+
|
|
227
|
+
@app.command("seed")
|
|
228
|
+
def seed_database(app, args, extra):
|
|
229
|
+
"""Populate the database with initial data."""
|
|
230
|
+
with app.get_db_session() as session:
|
|
231
|
+
# ... insert seed records ...
|
|
232
|
+
session.commit()
|
|
233
|
+
print("Database seeded.")
|
|
234
|
+
|
|
235
|
+
if __name__ == "__main__":
|
|
236
|
+
app.start()
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
A command that accepts its own flags — parse `extra` with argparse:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
import argparse
|
|
243
|
+
|
|
244
|
+
@app.command("seed")
|
|
245
|
+
def seed_database(app, args, extra):
|
|
246
|
+
p = argparse.ArgumentParser(prog="spiderweb seed")
|
|
247
|
+
p.add_argument("--dry-run", action="store_true")
|
|
248
|
+
opts = p.parse_args(extra)
|
|
249
|
+
|
|
250
|
+
if opts.dry_run:
|
|
251
|
+
print("Dry run — no changes written.")
|
|
252
|
+
return
|
|
253
|
+
|
|
254
|
+
with app.get_db_session() as session:
|
|
255
|
+
session.commit()
|
|
256
|
+
print("Database seeded.")
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
```shell
|
|
260
|
+
web seed --dry-run
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Run any custom command the same way as a built-in:
|
|
264
|
+
|
|
265
|
+
```shell
|
|
266
|
+
web --app myapp:app seed
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
Or, with `pyproject.toml` configured, just:
|
|
270
|
+
|
|
271
|
+
```shell
|
|
272
|
+
web seed
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
> [!NOTE]
|
|
276
|
+
> The decorated function is still a regular Python function. Applying `@app.command()` doesn't change it in any way — you can still call it directly in your own code.
|
|
277
|
+
|
|
278
|
+
You can register as many custom commands as you like. Pick meaningful names; they'll show up in the error message if someone types an unrecognised command, so short and descriptive is best.
|
|
279
|
+
|
|
280
|
+
## configuration reference
|
|
281
|
+
|
|
282
|
+
| Option | Description |
|
|
283
|
+
|---|---|
|
|
284
|
+
| `--app MODULE:ATTR` | The app to use, in `module:attribute` form. Overrides `SPIDERWEB_APP` and `pyproject.toml`. |
|
|
285
|
+
| `SPIDERWEB_APP` | Environment variable. Overrides `pyproject.toml`, overridden by `--app`. |
|
|
286
|
+
| `[tool.spiderweb] app` | `pyproject.toml` key. Lowest priority; used when neither of the above is set. |
|
|
287
|
+
| `[tool.spiderweb] asgi` | `pyproject.toml` boolean. When `true`, `serve` defaults to ASGI mode. Overridden by `--asgi` / `--wsgi`. |
|
|
288
|
+
| `[tool.spiderweb] migrations_dir` | Path to the Alembic migrations directory, relative to `pyproject.toml`. Defaults to `migrations`. |
|
|
289
|
+
|
|
290
|
+
### `serve` options
|
|
291
|
+
|
|
292
|
+
| Flag | Description |
|
|
293
|
+
|---|---|
|
|
294
|
+
| `--asgi` | Start in ASGI mode via uvicorn instead of WSGI. |
|
|
295
|
+
| `--wsgi` | Force WSGI mode even when `asgi = true` is set in `pyproject.toml`. |
|
|
296
|
+
| `--addr ADDR` | Bind address. Overrides the value stored in the app. |
|
|
297
|
+
| `--port PORT` | Port number. Overrides the value stored in the app. |
|
|
298
|
+
|
|
299
|
+
### `makemigrations` options
|
|
300
|
+
|
|
301
|
+
| Flag | Description |
|
|
302
|
+
|---|---|
|
|
303
|
+
| `-m MESSAGE` / `--message MESSAGE` | Short description for the migration. |
|
|
304
|
+
| `--empty` | Create a blank migration without autogenerate. |
|
|
305
|
+
|
|
306
|
+
### `migrate` options
|
|
307
|
+
|
|
308
|
+
| Flag | Description |
|
|
309
|
+
|---|---|
|
|
310
|
+
| `REVISION` | Target revision (default: `head`). Accepts revision IDs, `+N`/`-N` relative specs, `zero`, or `base`. |
|
|
311
|
+
| `--fake` | Stamp the database at the target revision without running SQL. |
|
{spiderweb_framework-2.2.1 → spiderweb_framework-2.4.0}/docs/middleware/custom_middleware.md
RENAMED
|
@@ -57,7 +57,7 @@ This is a helper function that is available for you to override; it's not often
|
|
|
57
57
|
|
|
58
58
|
## post_process(self, request: Request, response: HttpResponse, rendered_response: str) -> str | bytes:
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
[!badge New in 1.3.0!]
|
|
61
61
|
|
|
62
62
|
After `process_request` and `process_response` run, the response is rendered out into the raw text that is going to be sent to the client. Right before that happens, `post_process` is called on each middleware in the same order as `process_response` (so the closer something is to the beginning of the middleware list, the more important it is).
|
|
63
63
|
|