Skip to main content

bot403 for Python

Bot403 is an invisible bot shield for HTML forms: one script tag makes the browser solve a small proof of work, and your server checks it with one call. This package is that call for Python. It uses only the standard library. The free plan covers 5,000 checks a month.

Install

pip install bot403

Set up

  1. Create a site at bot403.com. You get a public key (pk_live_…) and a secret key (sk_live_…).

  2. Add the script tag to the page with the form, before </body>:

    <script src="https://bot403.com/v1/bot403.js" data-bot403-key="pk_live_…" defer></script>
    
  3. Put the secret key in the environment of your server, never in a page or in Git:

    BOT403_SECRET_KEY=sk_live_…
    
  4. Check the form on submit (Flask):

    from bot403 import Bot403, Bot403Error
    from flask import Flask, abort, request
    
    app = Flask(__name__)
    bot403 = Bot403()  # reads BOT403_SECRET_KEY
    
    @app.post("/contact")
    def contact():
        try:
            # Post the whole form: Bot403 reads the _bot403 field and the honeypot field.
            result = bot403.verify_form(request.form)
        except Bot403Error as e:
            if e.status != 0:
                raise
            result = None  # Bot403 did not answer: let the form through
        # Refuse when ok is false, except for reason "quota".
        if result and not result.ok and result.reason != "quota":
            abort(400)
        return "Thanks."
    

    Django: bot403.verify_form(request.POST). With fetch and JSON, send the token alone: bot403.verify(token).

Answers

verify and verify_form return a Result. A token that fails is not an exception.

result.ok / result.reason Meaning What to do
True A browser solved the puzzle for this site. The token was not used before. Accept.
invalid The token is missing, damaged, or wrong. Reject.
expired The challenge is older than the site's expiry (default 10 minutes). Reject. Ask the visitor to send again.
replay The token was used before. Reject.
wrong_site The token belongs to a different site. Reject. Check the keys.
honeypot The hidden honeypot field had a value. Reject, or show a fake success.
quota (HTTP 402) Only in a capped month, after two calendar months over the plan in a row. The token is not used up. Your choice. The example lets the form through.

Bot403Error means the request failed as a whole. e.status is the HTTP status (401 wrong key, 429 too many verify calls a minute, 413 body over 64 KB), or 0 when the network failed (e.code == "network"). Decide what your server does when Bot403 does not answer. The example lets the form through.

Options: Bot403(secret_key=None, base_url="https://bot403.com", timeout=10).

All answers and reasons: bot403.com/docs/verify. API reference: bot403.com/docs/api.

Test

The tests run against a local fake of the API. They make no network calls.

uv run --with pytest --with . python -m pytest -q tests

License

MIT. See LICENSE.

Metadata

Release files for bot403 0.1.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 bot403 0.1.0
File Size Uploaded Provenance Actions
bot403-0.1.0.tar.gz 5.5 kB Without provenance Details for bot403-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bot403 0.1.0
File Interpreter ABI Platform Actions
bot403-0.1.0-py3-none-any.whl Python 3 none any Details for bot403-0.1.0-py3-none-any.whl

Total release size: 10.7 kB

Release files / bot403-0.1.0.tar.gz

Download URL bot403-0.1.0.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
771476c0951212195ab6a18b3366ce945409fe9b6c5852b36894b70353b156a5
BLAKE2b-256 checksum
How to use checksums
66c72bd2f78d2656e0ed46b0921c62f09d302afcd7dcce1b3bf48f6d3ba428e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / bot403-0.1.0-py3-none-any.whl

Download URL bot403-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f16d0f96a291696059004736713e38a3f48fb956d293af3cca7426c522952850
BLAKE2b-256 checksum
How to use checksums
e51d47ba2bbf438b18a921fad26bf24e13bddbcac37169b3511a836414303735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for bot403 0.1.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

0.1.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