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.
You can find more documentation 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 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.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cloudstile-1.0.2.tar.gz.
File metadata
- Download URL: cloudstile-1.0.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.11 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b914bde882ffa3c26b4dfaf7b7ea6b7f27bb462bace99b0491abaf1bae9f79b7
|
|
| MD5 |
ab7926a8b4d2bc89c31c4f62cab224d2
|
|
| BLAKE2b-256 |
65e1cc41c7df13526eaf8eef9fda5312ef73fed10efd26a46fff8501c0617ff3
|
File details
Details for the file cloudstile-1.0.2-py3-none-any.whl.
File metadata
- Download URL: cloudstile-1.0.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c02babd074f9195005351457a655d8bcddf8c616f1595a37b35f828aadb2c0ab
|
|
| MD5 |
782412b0424494d8ab61696e1dbc1a6b
|
|
| BLAKE2b-256 |
dd8af636694cc2b99b3f81af66116e2cffbfaba115b134e0301781494b7c4867
|