Skip to main content

Protect against bots and DDoS attacks

Project description

flask-Humanify

A strong bot protection system for Flask with many features: rate limiting, special rules for users, web crawler detection, and automatic bot detection.

Github PyPI Libraries.io


from flask import Flask
from flask_Humanify import Humanify

app = Flask(__name__)
humanify = Humanify(app, challenge_type="one_click", image_dataset="ai_dogs")

# Register the middleware to deny access to bots
humanify.register_middleware(action="challenge")

@app.route("/")
def index():
    """
    A route that is protected against bots and DDoS attacks.
    """
    return "Hello, Human!"

if __name__ == "__main__":
    app.run()

Advanced Protection Rules

You can customize bot protection with advanced filtering rules:

# Protect specific endpoints with regex patterns
humanify.register_middleware(
    action="challenge",
    endpoint_patterns=["api.*", "admin.*"]  # Protect all API and admin endpoints
)

# Protect specific URL paths
humanify.register_middleware(
    action="deny_access",
    url_patterns=["/sensitive/*", "/admin/*"]  # Deny bot access to sensitive areas
)

# Exclude certain patterns from protection
humanify.register_middleware(
    endpoint_patterns=["api.*"],
    exclude_patterns=["api.public.*"]  # Don't protect public API endpoints
)

# Filter by request parameters
humanify.register_middleware(
    request_filters={
        "method": ["POST", "PUT", "DELETE"],  # Only protect write operations
        "args.admin": "true",                # Only when admin=true query parameter exists
        "headers.content-type": "regex:application/json.*"  # Match content type with regex
    }
)

Not using the middleware:

@app.route("/")
def index():
    """
    A route that is protected against bots and DDoS attacks.
    """
    if humanify.is_bot:
        return humanify.challenge()
    return "Hello, Human!"

Usage

Installation

Install the package with pip:

pip install flask-humanify --upgrade

Import the extension:

from flask_humanify import Humanify

Add the extension to your Flask app:

app = Flask(__name__)
humanify = Humanify(app)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_humanify-0.2.1.tar.gz (82.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_humanify-0.2.1-py3-none-any.whl (82.4 MB view details)

Uploaded Python 3

File details

Details for the file flask_humanify-0.2.1.tar.gz.

File metadata

  • Download URL: flask_humanify-0.2.1.tar.gz
  • Upload date:
  • Size: 82.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for flask_humanify-0.2.1.tar.gz
Algorithm Hash digest
SHA256 86952996dd3e8c6d5c18c908fc085c15d78526e98936b93072299b1f77382dda
MD5 c2f544b4fc2b90ae06b45978de8d5a80
BLAKE2b-256 c08daea871c0535ca6445a184a3a747646f840e83905b659cc00f6a74e19c5b7

See more details on using hashes here.

File details

Details for the file flask_humanify-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: flask_humanify-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 82.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for flask_humanify-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 eaac1132da34de687e25e12fd8db57c5671eae9c155f50b674093dd9d478219c
MD5 7fe52dc514a5644fd92a223b1d501d7b
BLAKE2b-256 fba9a076a9b03a7431aed95042a963ecc2a055b95aae9fce02b3b41627e57fd9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page