Skip to main content

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: 3600 so 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_API_KEY DevGuard API key (optional) 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.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for devguard-python-guard 1.0.0
File Size Uploaded Provenance Actions
devguard_python_guard-1.0.0.tar.gz 11.0 kB Without provenance Details for devguard_python_guard-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for devguard-python-guard 1.0.0
File Interpreter ABI Platform Actions
devguard_python_guard-1.0.0-py3-none-any.whl Python 3 none any Details for devguard_python_guard-1.0.0-py3-none-any.whl

Total release size: 22.3 kB

Release files / devguard_python_guard-1.0.0.tar.gz

Download URL devguard_python_guard-1.0.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5d31d97afb33ab4c67451d935314671f0337cf5f0d55fce9961d2aa2f3457a31
BLAKE2b-256 checksum
How to use checksums
d9da6a61d2086d2ff55ab184f9eaf96088e4883615642e1a0232292d51cdb2de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Release files / devguard_python_guard-1.0.0-py3-none-any.whl

Download URL devguard_python_guard-1.0.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b70eac17f8ae365b596303ce9c7e24485518d6667f07cbf62a023871862852b2
BLAKE2b-256 checksum
How to use checksums
f286143c84668c9fb51a25cd584cbb2e0d83603960ca306d396ca4a73d6cee0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.7

Security for devguard-python-guard 1.0.0

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page