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.1.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.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cloudstile-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 eb96a68159c4b4d49a8c6d6a8bcbc88e5dcf26dd748401bd880929df4554a88e
MD5 4835fa7206ef236546091605027b7e70
BLAKE2b-256 ad9a4b1e75a0a2085c007a7104752b83fbf099f3778826a8d0d30f9fc840ec4f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cloudstile-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2ae727f7c53099d28bad2980eaefafa3a7c39fff01df6e9010570a29ec21f00
MD5 b286750327e9aba630e0fb506073897c
BLAKE2b-256 97a7caaa4da2387a16b0bb00e851252ca2f4879a6e67ecb25e3fce0decc0f535

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