Secweb
Secweb is a pack of security middlewares for fastApi and starlette servers it includes CSP, HSTS, and many more
What it is and what it does
Secweb is a middleware package that automatically injects security headers into Starlette-based application responses. It provides 16 security headers including Content-Security-Policy, HTTP Strict Transport Security, X-Frame-Options, and others, with sensible defaults aligned to MDN and OWASP recommendations. You can use it as a single SecWeb class that applies all headers at once, or import individual header functions to apply only what you need. Headers are customizable via an options dictionary, and some support advanced features like nonce generation for inline scripts and styles, or report-only modes for testing policies without enforcement.
The package has no external runtime dependencies beyond Starlette itself, making it lightweight to add to existing projects. Configuration is minimal—often just a single line—but flexible enough to disable specific headers or override defaults. It targets Python >= 3.10 and is actively maintained.
Use it for:
- Add CSP, HSTS, and clickjacking protection to a Starlette application in one call without writing middleware boilerplate.
- Gradually roll out a Content-Security-Policy by enabling report-only mode to collect violations before enforcing.
- Generate per-request nonces for inline scripts and styles in a template route to allow CSP while keeping inline code.
- Protect a Starlette application with security headers when you cannot or do not want to use a reverse proxy.
- Customize individual security policies (e.g., set HSTS max-age or Cache-Control directives) while keeping others at defaults.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Secweb applies security headers (CSP, HSTS, X-Frame-Options, and 13 others) to FastAPI and Starlette applications with minimal configuration and no external runtime dependencies.
Yes. Secweb is worth installing if you use Starlette and want security headers without external dependencies or complex configuration. It is actively maintained, has no known vulnerabilities, and offers both simplicity (one-line setup) and flexibility (per-header customization). The MPL-2.0 license is permissive for use; only modifications to the package itself trigger copyleft obligations. The main consideration is the Python >= 3.10 requirement.
Install
secweb on PyPI
pip
pip install secwebuv
uv add secwebpoetry
poetry add secwebInstalling Secweb
Before you install
Low install friction: pure Python wheel with no runtime dependencies. Active maintenance with a recent release (15 days old) and steady repository activity.
License in practice
Licensed under MPL-2.0 (copyleft). You must disclose source code modifications and distribute under the same license if you modify the package itself, though using it unmodified in your application does not trigger these obligations.
Quickstart
pip install Secweb
from Secweb import SecWeb
SecWeb(app=app)
Requires Python >= 3.10 and Starlette.
Verify before relying
- Whether the 16 headers listed in the description are all implemented in version 2.0.0 or if some (like PermissionsPolicy) remain in development.
- Whether nonce generation for CSP is cryptographically sound and suitable for production use.
- Whether the package works with frameworks other than those built on Starlette.
Package facts
| License | MPL-2.0 (copyleft) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 15 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 361,236/month — #7,240 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: secweb-2.0.0-py3-none-any.whl
Keywords: fastapi security header, security header, starlette security header, secweb, fastapi csp, starlette csp, csp
Tags
More Security packages
Provides Python bindings to the FreeDesktop.org…
permissive · top 1,000 on PyPI
msalMSAL for Python handles OAuth2 and OpenID…
permissive · top 1,000 on PyPI
joserfcjoserfc implements JOSE standards (JWS, JWE,…
permissive · top 1,000 on PyPI
AuthlibAuthlib provides a complete implementation of…
permissive · top 1,000 on PyPI
argon2-cffi-bindingsProvides low-level CFFI bindings to the…
permissive · top 1,000 on PyPI
adalADAL for Python authenticates applications with…
permissive · top 1,000 on PyPI
secureApplies HTTP security headers to Python web…
permissive · top 5,000 on PyPI
hstspreloadProvides a single function to check whether a…
permissive · top 15,000 on PyPI
django-cspDjango-CSP adds Content-Security-Policy headers…
permissive · top 5,000 on PyPI
starlette-contextMiddleware for Starlette that stores and…
permissive · top 5,000 on PyPI
starlette-csrfStarlette middleware that protects web…
permissive · top 15,000 on PyPI
flask-talismanFlask extension that automatically sets HTTP…
permissive · top 5,000 on PyPI
starlette-compressMiddleware for Starlette and FastAPI that…
permissive · top 5,000 on PyPI
sse-starletteProvides Server-Sent Events streaming for…
permissive · top 1,000 on PyPI
django-permissions-policySets the Permissions-Policy HTTP header on…
permissive · top 15,000 on PyPI
starlette-exporterCollects and exports Prometheus metrics for…
permissive · top 5,000 on PyPI