DevGuard Python Guard (devguard-python-guard)
Official zero-dependency Python guard for DevGuard anti-theft protection, domain allowlisting, invoice milestone autolock enforcement, and SEO-safe HTTP 503 lockouts.
Supports FastAPI, Starlette (ASGI), Django, and Flask (WSGI).
Key Features
- Zero External Dependencies: Operates exclusively using the Python Standard Library (
urllib,json,re,time,threading). - Fail-Safe Open Policy: Network timeouts, DNS issues, or unreachable APIs will never interrupt client application traffic.
- Domain Authorization: Enforces authorized hosting domains with support for wildcard subdomains (
*.example.com). - Milestone Autolock: Automatically queries project status from the DevGuard API with local in-memory TTL caching.
- SEO-Safe HTTP 503: Emits HTTP status 503 with
Retry-After: 3600so search crawlers do not drop site ranking during payment disputes.
Installation
pip install devguard-python-guard
Usage
1. FastAPI / Starlette (ASGI)
from fastapi import FastAPI
from devguard_python_guard import DevGuardASGIMiddleware
app = FastAPI()
app.add_middleware(
DevGuardASGIMiddleware,
project_id="proj_your_project_id",
allowed_domains=["example.com", "*.example.com"],
fail_safe=True, # Default: True (fail-safe open)
cache_ttl=300, # 5-minute status cache
)
@app.get("/")
def home():
return {"message": "Hello World"}
2. Django (WSGI)
In myproject/wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
from devguard_python_guard import DevGuardWSGIMiddleware
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
application = get_wsgi_application()
application = DevGuardWSGIMiddleware(
application,
project_id=os.getenv("DEVGUARD_PROJECT_ID"),
allowed_domains=["example.com", "*.example.com"],
fail_safe=True,
)
3. Flask (WSGI)
from flask import Flask
from devguard_python_guard import DevGuardWSGIMiddleware
app = Flask(__name__)
app.wsgi_app = DevGuardWSGIMiddleware(
app.wsgi_app,
project_id="proj_your_project_id",
allowed_domains=["example.com", "*.example.com"],
fail_safe=True,
)
@app.route("/")
def index():
return "Hello Flask"
Environment Variables
You can configure DevGuard via environment variables or explicitly in code:
| Variable | Description | Default |
|---|---|---|
DEVGUARD_PROJECT_ID |
Project ID from DevGuard dashboard | "" |
DEVGUARD_API_URL |
DevGuard API endpoint | https://api.devguard.uk |
DEVGUARD_SDK_KEY |
Preferred project SDK key (Portal → Project SDK key) | None |
DEVGUARD_API_KEY |
Legacy API / Master Secret fallback when SDK key unset | None |
DEVGUARD_ALLOWED_DOMAINS |
Comma-separated allowed domains | None |
DEVGUARD_FAIL_SAFE |
open (true) or closed (false) |
open |
DEVGUARD_CACHE_TTL |
Cache duration in seconds | 300 |
DEVGUARD_TRUST_PROXY |
Trust X-Forwarded-Host |
false |
Metadata
Release files for devguard-python-guard 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| devguard_python_guard-1.0.1.tar.gz | 11.2 kB | Without provenance | Details for devguard_python_guard-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| devguard_python_guard-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for devguard_python_guard-1.0.1-py3-none-any.whl |
Total release size: 22.6 kB
Release files / devguard_python_guard-1.0.1.tar.gz
| Download URL | devguard_python_guard-1.0.1.tar.gz |
|---|---|
| Size | 11.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
525bf3ebff9fa1019376bddc2a2a7981159c629628aeb49384aaf688222f6858
|
|
BLAKE2b-256 checksum How to use checksums |
0f3e8c59381760aefdaf67de23c18972cecf359500e0f3d5a33316f1a3ee58bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / devguard_python_guard-1.0.1-py3-none-any.whl
| Download URL | devguard_python_guard-1.0.1-py3-none-any.whl |
|---|---|
| Size | 11.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ed1c1e8e3ac75028920d0614f617e6df57cf4ee283d328ae871db88bcc055dff
|
|
BLAKE2b-256 checksum How to use checksums |
ac1d1d08b43ed7034ba21c1d08fb2343a6ed2e88629d79c22374056c22fc6f78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for devguard-python-guard 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.