secure
A lightweight package that adds security headers for Python web frameworks.
What it is and what it does
Secure centralizes HTTP security header management for Python web applications, replacing ad hoc header strings scattered across routes and middleware. Instead of copying header policy into view code, you configure one Secure instance with an opinionated preset (BALANCED, BASIC, or STRICT) and apply it consistently across all responses. The package handles Content-Security-Policy, Strict-Transport-Security, referrer policy, permissions policy, and browser protection headers.
It supports both synchronous and asynchronous response objects through a small public API and typed builders for custom policies. Middleware integrations for WSGI and ASGI let you apply headers app-wide rather than per-route. The package has no external dependencies and is fully typed, making it straightforward to integrate into existing frameworks.
Use it for:
- Apply HSTS, CSP, and referrer policies consistently across a web application via middleware.
- Tune specific security headers for compliance or hardening without rewriting header strings in every route.
- Start with BALANCED preset for a modern baseline and upgrade to STRICT when deploying a high-security application.
- Validate and normalize dynamically composed headers before emission to catch policy drift.
- Migrate legacy applications from ad hoc header code to a centralized, maintainable policy object.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Applies HTTP security headers to Python web responses through a single configurable object, supporting both WSGI and ASGI frameworks with preset policies and custom builder options.
Yes. Secure solves a real problem—header policy drift in web applications—with zero dependencies, active maintenance, and a clean API. The MIT license and support for current Python versions (3.10+) make it a low-risk addition. Install it if you manage HTTP security headers in any Python web framework; the preset defaults are sensible and the builder API scales to custom policies.
Install
secure on PyPI
pip
pip install secureuv
uv add securepoetry
poetry add secureInstalling secure
Before you install
Low friction: zero runtime dependencies, pure Python wheel, requires Python 3.10+. Active maintenance with recent release (114 days ago) and 1049 repository stars.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal obligations.
Quickstart
pip install secure
from secure import Secure
from secure.middleware import SecureASGIMiddleware
secure_headers = Secure.with_default_headers()
# Apply via app.add_middleware(SecureASGIMiddleware, secure=secure_headers)
Requires Python 3.10 or later.
Verify before relying
- Whether the package's header policies align with current OWASP or industry security recommendations.
- Performance overhead of header application at scale or in high-throughput scenarios.
- Coverage of emerging security headers beyond the three preset tiers.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 114 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,109,290/month — #3,289 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: secure-2.0.1-py3-none-any.whl
Keywords: security, headers, web, framework, HTTP
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
django-cspDjango-CSP adds Content-Security-Policy headers…
permissive · top 5,000 on PyPI
flask-talismanFlask extension that automatically sets HTTP…
permissive · top 5,000 on PyPI
hstspreloadProvides a single function to check whether a…
permissive · top 15,000 on PyPI
SecwebSecweb applies security headers (CSP, HSTS,…
copyleft · top 15,000 on PyPI
django-permissions-policySets the Permissions-Policy HTTP header on…
permissive · top 15,000 on PyPI
asgi-csrfASGI middleware that protects web applications…
permissive · top 15,000 on PyPI
starlette-csrfStarlette middleware that protects web…
permissive · top 15,000 on PyPI
piccolo-apiExposes Piccolo ORM tables as REST endpoints in…
permissive · top 15,000 on PyPI
fastapi-csrf-protectAdds stateless CSRF protection to FastAPI…
permissive · top 15,000 on PyPI
zope.securityProvides a generic security framework for…
unclear · top 15,000 on PyPI