Skip to main content

Unofficial Cloudflare Turnstile library for Python with async and sync support.

Project description

Cloudstile

An unofficial Cloudflare Turnstile library with both asynchronous and synchronous support out of the box.

📥 Installation

Cloudstile is available for download via PyPI. To install it, simply do:

pip install cloudstile

🎭 Example

Here are some basic examples of how to validate a user's turnstile token.

[!WARNING] These examples expect the user's IP to be transparent. If you're using something like Cloudflare's proxy service, then you'll need to access the corresponding header for your use case.

🍷 Quart (Asynchronous)

from quart import Quart, request, jsonify
from cloudstile import AsyncTurnstile

app = Quart(__name__)
turnstile = AsyncTurnstile(token="...")

@app.route("/submit", methods=["POST"])
async def submit():

    body = await request.form

    response = await turnstile.validate(
        body.get("cf-turnstile-response", "..."),
        request.remote_addr,
    )

    return jsonify(response.model_dump()) # <- Response is a pydantic object

🏃‍♀️ FastAPI (Asynchronous)

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
from cloudstile import AsyncTurnstile

app = FastAPI()
turnstile = AsyncTurnstile(token="...")

@app.post("/submit")
async def submit(request: Request):

    body = await request.form()

    response = await turnstile.validate(
        body.get("cf-turnstile-response", "..."),
        request.client.host,
    )

    return JSONResponse(response.model_dump()) # <- Response is a pydantic object

🦥 Flask (Synchronous)

from flask import Flask, request, jsonify
from cloudstile import SyncTurnstile

app = Flask(__name__)
turnstile = SyncTurnstile(token="...")

@app.route("/submit", methods=["POST"])
def submit():

    body = request.form

    response = turnstile.validate(
        body.get("cf-turnstile-response", "..."),
        request.remote_addr,
    )

    return jsonify(response.model_dump()) # <- Response is a pydantic object

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

cloudstile-2.0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

cloudstile-2.0.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file cloudstile-2.0.2.tar.gz.

File metadata

  • Download URL: cloudstile-2.0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.4 Linux/7.0.3-1-cachyos

File hashes

Hashes for cloudstile-2.0.2.tar.gz
Algorithm Hash digest
SHA256 eeec944e8312407d1396e1f5e359384b0ac54776866f567db77851cb0dcc1c2a
MD5 c2edb55adccfa077774997a5fa27a08c
BLAKE2b-256 32c19d4470773a452f317404336a2858ce0385a1299b050157938e043ffbc884

See more details on using hashes here.

File details

Details for the file cloudstile-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: cloudstile-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.14.4 Linux/7.0.3-1-cachyos

File hashes

Hashes for cloudstile-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b567a9f303739a935929e0b595c26a812f4a68944bf1bd37e78c7d8fe569c257
MD5 34be76a980e69e78a6378689a6529900
BLAKE2b-256 1e38eec1eaf4e24769ec520f66b18089494e3aa1e3061ef16c8020d881d27c13

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