skillfed

Secweb

Secweb is a pack of security middlewares for fastApi and starlette servers it includes CSP, HSTS, and many more

secweb v2.0.0 361.2K downloads/30d#7,240 on PyPI82
Copyleft license MPL-2.0 Active released

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 secweb

uv

uv add secweb

poetry

poetry add secweb

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

starlette security headerscsp middlewarehttp security headerscontent security policyhsts strict transport securityx-frame-options middlewaresecurity header middleware
starlette-middlewarehttp-security

More Security packages