Skip to main content
Peak: solve Cloudflare Turnstile and the 5s challenge

turnstile-curl

turnstile-curl is a curl_cffi companion that solves Cloudflare Turnstile without a browser, so a curl_cffi request that hits a Turnstile wall comes back with a real token instead of a 403.

Why

curl_cffi forges a browser's TLS/JA3 handshake, which is why people reach for it. It has no JavaScript engine. Cloudflare Turnstile is a JS widget, so a managed or interactive challenge hands curl_cffi an interstitial HTML page or a 403, and there is nothing in-process that can run the challenge. This is the "curl_cffi cloudflare blocked" wall: the handshake is right, the request still fails.

turnstile-curl reads the Turnstile sitekey out of the returned markup, sends it to Peak, and gives you back the cf-turnstile-response token. curl_cffi still does the fetching, so you keep its speed and fingerprint.

Powered by Peak

This package uses Peak to solve Turnstile.

  • Solves Cloudflare Turnstile and the 5s challenge
  • $0.90 per 1,000 successful Turnstile solves, down to $0.35 at volume; failed solves cost nothing
  • 1,000 free solves to start, no card

Get your free API key · Docs · Pricing

Install

pip install turnstile-curl curl_cffi

curl_cffi is the transport you fetch pages with. It is an optional dependency here so the library imports cleanly without it; install it to fetch pages.

Quickstart

import os
from turnstile_curl import solve

# Free key at https://peak.fo. Reads PEAK_API_KEY by default.
os.environ.setdefault("PEAK_API_KEY", "pk_your_api_key")

# Fetch the protected page with curl_cffi, read the sitekey, solve via Peak.
token = solve("https://your-target.example/login")
print(token)  # -> "0.AgAAA..."  (the cf-turnstile-response value)

Send token as the cf-turnstile-response form field (or into the widget callback) on your next request.

Session: solve and resubmit in one shot

TurnstileSession wraps a curl_cffi session and keeps the same browser fingerprint through the whole flow.

from turnstile_curl import TurnstileSession

with TurnstileSession(api_key="pk_your_api_key", impersonate="chrome") as s:
    # Token only:
    token = s.solve("https://your-target.example/login")

    # Or solve + resubmit the form with the token injected, and keep the
    # authenticated response and cookies on the session:
    resp = s.solve_and_submit(
        "https://your-target.example/login",
        submit_url="https://your-target.example/verify",
        data={"username": "demo", "password": "demo"},
    )
    print(resp.status_code)

Already have the sitekey

Skip the fetch and call Peak directly.

from turnstile_curl import PeakClient

peak = PeakClient(api_key="pk_your_api_key")
token = peak.solve_turnstile(
    sitekey="0x4AAAAAAADnPIDROrmt1Wwj",
    url="https://your-target.example/login",
    # proxy="http://user:pass@ip:port",  # optional
)

Proxies

Pass proxy="http://user:pass@ip:port" to TurnstileSession, solve(), or PeakClient.solve_turnstile(). The same proxy is used for the page fetch and forwarded to Peak so the token is minted from the IP you will use it on.

Earn with your app ID

Pass your Peak app id and you earn 5% of every solve this tool makes, paid as solve credit. It is optional and does not affect solve success or speed; it only tells Peak which app to credit. Create an app id at peak.fo/dashboard/developer, details at peak.fo/earn.

from turnstile_curl import solve

# Pass app_id=, or set the PEAK_APP_ID env var instead.
token = solve("https://your-target.example/login", app_id="app_your_app_id")

app_id works the same on TurnstileSession(...) and PeakClient(...), and falls back to PEAK_APP_ID when omitted.

How it works

  1. curl_cffi fetches the page with a forged browser TLS/JA3 fingerprint.
  2. turnstile-curl parses the sitekey (and cData / action / pagedata when present) from the data-sitekey container or a turnstile.render(...) call.
  3. It calls POST https://api.peak.fo/solve with task_type: "turnstiletask", the sitekey, and the URL.
  4. Peak returns the token; you resubmit the form with it as cf-turnstile-response.

Peak also solves the Cloudflare 5s challenge (task_type: "cloudflare5stask"); this package focuses on Turnstile.

API

  • solve(url, *, api_key=None, impersonate="chrome", proxy=None, app_id=None) -> str: one-shot fetch + solve, returns the token.
  • TurnstileSession(api_key=None, *, impersonate="chrome", proxy=None, app_id=None): .get(), .solve(url), .detect_challenge(url), .solve_and_submit(url, ...).
  • PeakClient(api_key=None, *, app_id=None): .solve(challenge), .solve_turnstile(sitekey, url, ...).
  • parse_challenge(html, url) / find_sitekey(html): the extractor, if you fetch pages yourself.

The API key is read from PEAK_API_KEY unless you pass api_key=. The optional revenue-share app id is read from PEAK_APP_ID unless you pass app_id=.

Troubleshooting

Every exception subclasses TurnstileCurlError, so one except catches them all. Each has its own class and a message you can grep for.

  • SitekeyNotFound: No Turnstile sitekey found in the page. The HTML curl_cffi received has no data-sitekey and no turnstile.render(...) call. Either the URL is not behind Turnstile, or the widget is built by a script bundle after load, and curl_cffi runs no JavaScript. Open the page in a browser, copy the sitekey from the network tab or the bundle, and call PeakClient.solve_turnstile(sitekey, url). How to find a Cloudflare Turnstile sitekey shows where sites hide it.
  • MissingAPIKey: No Peak API key. Neither api_key= nor PEAK_API_KEY held a key. Keys start with pk_; the free one comes from the dashboard.
  • PeakAPIError Peak answered with success: false, and the message is Peak's own reason. The exception carries .status_code and .payload for logging. Common causes: an empty balance, a sitekey that does not belong to the URL, or a proxy= Peak could not connect through. The Cloudflare Turnstile error codes post covers the widget-side codes (110200, 300030, 600010 and the rest) that sit behind many failed solves.
  • TurnstileCurlError: curl_cffi is not installed. The package imports without curl_cffi, but solve(url) and TurnstileSession need it to fetch the page. Run pip install curl_cffi, or skip the fetch with PeakClient.solve_turnstile(sitekey, url).
  • solve_and_submit returns 403 or the form page again. The token was minted and the site refused the submit. Check three things. The field name: most sites read cf-turnstile-response, some read their own JSON key. The age: a token is single-use and expires 300 seconds after it is issued, so submit it right away and never reuse it. The IP: pass proxy= so the token is minted from the address that submits it. The cf-turnstile-response token explained and cf-turnstile-response is empty cover the field, and Cloudflare Turnstile 403 covers the refusal.
  • The first response is a "Just a moment..." page with no sitekey. That page is the managed 5-second challenge, a separate check from the Turnstile widget. It wants a cf_clearance cookie, which this package does not fetch. cloudscraper-turnstile handles that path without a browser. Turnstile token vs cookie explains the difference, and the Cloudflare 5-second challenge explained covers the interstitial.

Two longer reads for this stack: How to scrape Cloudflare-protected sites without getting blocked (also on Hashnode) and the 2026 Turnstile developer guide.

Same pattern for other stacks: cloudscraper-turnstile (a requests.Session drop-in, no browser) · scrapy-turnstile · scrapling-turnstile · playwright-turnstile · patchright-turnstile · camoufox-turnstile · nodriver-turnstile · pydoll-turnstile · drissionpage-turnstile · selenium-turnstile · botasaurus-turnstile · crawlee-turnstile · puppeteer-extra-plugin-turnstile · browser-use-turnstile · crawl4ai-turnstile. Full list in awesome-turnstile-solvers.

If you want to know what the widget does before it hands out a token, cloudflare-turnstile-reversed documents the challenge flow, the widget parameters and the fingerprinting it runs.

Legitimate use

For automation, QA, and scraping public data you are allowed to access. Respect each target's Terms of Service and robots.txt, and rate-limit yourself. Do not use this for credential stuffing or to access data you have no right to.

License

MIT. See LICENSE.

Metadata

Release files for turnstile-curl 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for turnstile-curl 0.2.2
File Size Uploaded Provenance Actions
turnstile_curl-0.2.2.tar.gz 14.1 kB Without provenance Details for turnstile_curl-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for turnstile-curl 0.2.2
File Interpreter ABI Platform Actions
turnstile_curl-0.2.2-py3-none-any.whl Python 3 none any Details for turnstile_curl-0.2.2-py3-none-any.whl

Total release size: 27.8 kB

Release files / turnstile_curl-0.2.2.tar.gz

Download URL turnstile_curl-0.2.2.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
199fefa699f8a5d58d49f83344ef6fca878990c0ae503b8a3d6a5c03397bf7b2
BLAKE2b-256 checksum
How to use checksums
8c764ec5554c07bf8c4eee990cf2c1d02fa42269e68c3c89356042352ac16ce6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / turnstile_curl-0.2.2-py3-none-any.whl

Download URL turnstile_curl-0.2.2-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1e8b405e28cb6cf239344344aee7c77d050d1822733db2af99b3480a04a1ab2
BLAKE2b-256 checksum
How to use checksums
8d40592116b83f28af4f82b50aad0688608051ff9e431a519f54bc875b5b745c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for turnstile-curl 0.2.2

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.

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