Skip to main content

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

Project description

CloudStile

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

You can find more documention on how to use CloudStile in our examples or our wiki.

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

Note: These examples expect the user's IP to be transparent, if you're using something like Cloudflare's proxy 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.dict()) # <- 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.dict()) # <- 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.dict()) # <- 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-1.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

cloudstile-1.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cloudstile-1.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10

File hashes

Hashes for cloudstile-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0784a86f9899802541fa07879a754aedd51eac4277644f32a131d7086c136ea
MD5 a73d3f7cab1d7950ab61489a81e844c2
BLAKE2b-256 b23665801f4bbb1ee7f6f98b64dd4124538be90839a52b53bf3a690dec752675

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cloudstile-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10

File hashes

Hashes for cloudstile-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9c165281ad55a210bc2237df4fb5c8068c0075e5ff507f1e14a20174326abcf
MD5 3e9ee479624df91fd060811a0a7bcb2f
BLAKE2b-256 a3d502e29e79285dd36aef44876710154722eea3e7f035180109855c520c0116

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