pydoll-turnstile
pydoll-turnstile solves Cloudflare Turnstile on a pydoll tab. It reads the sitekey, gets a token from Peak, and writes it into the widget so the protected form or navigation proceeds.
Why
pydoll drives Chrome over the DevTools Protocol with no webdriver, and it ships its own Turnstile helper, tab.expect_cloudflare_turnstile(), which clicks the checkbox for you. On a clean residential IP that click is often enough.
On a datacenter IP it often isn't. The challenge renders, the click lands, and no token arrives, because Cloudflare scores the IP and the session before it scores the click. For those pages this package asks Peak for a token and injects it as the cf-turnstile-response value, then calls the widget's success callback.
Powered by Peak
This package uses Peak to solve Turnstile.
- $0.90 per 1,000 successful Turnstile solves, down to $0.35 at volume
- A failed solve is not billed
- 1,000 free solves to start, no card
→ Get your free API key · Docs · Pricing
Install
pip install pydoll-turnstile pydoll-python
Use 0.1.1 or later. Version 0.1.0 does not work with pydoll (see Troubleshooting).
Quickstart
import asyncio
import os
from pydoll.browser import Chrome
from pydoll_turnstile import solve_turnstile
os.environ["PEAK_API_KEY"] = "pk_your_api_key"
async def main():
async with Chrome() as browser:
tab = await browser.start()
await tab.go_to("https://protected.example/login")
# Reads the sitekey, solves via Peak, injects the token.
await solve_turnstile(tab)
# the form / navigation can now proceed
asyncio.run(main())
How it works
- Read the sitekey. An
execute_scriptDOM scan finds thedata-sitekeyattribute, or a0x...sitekey set through a JSrender()call in the page source. - Solve via Peak.
POST https://api.peak.fo/solvewithtask_type: "turnstiletask", the sitekey, and the tab's current URL. The call runs in a worker thread so the event loop stays free. Passproxy=to mint the token from your browser's egress IP. - Inject the token.
execute_scriptsets everycf-turnstile-responsefield, firesinput/change, and calls the function named in the widget'sdata-callbackattribute.
API
await solve_turnstile(
tab, # a pydoll tab with execute_script
api_key=None, # defaults to env PEAK_API_KEY
proxy=None, # optional http://user:pass@ip:port, forwarded to Peak
sitekey=None, # override auto-detection (e.g. widget in a frame)
url=None, # defaults to the tab's current URL
task_type="turnstiletask",
timeout=180.0,
) -> str # the injected token
read_sitekey(tab), inject_token(tab, token), and current_url(tab) are exposed for finer control. inject_token returns True when it found and called a data-callback function, and False when it only filled the field.
The API key is read from PEAK_API_KEY by default; you can also pass it explicitly. Never hardcode a real key.
Troubleshooting
Every failure raises PeakError with a string you can grep for. The last three cases raise nothing.
- Every solve fails on 0.1.0. pydoll's
execute_scriptreturns the whole CDP response ({"id": ..., "result": {"result": {"value": ...}}}). Version 0.1.0 unwrapped one level too few and sent that dictionary to Peak as the sitekey and the URL. 0.1.1 fixes the unwrap; it was checked against pydoll 3.0.1 on a live Chrome. Runpip install -U pydoll-turnstile. PeakError: No Turnstile sitekey found on the page.The call ran before the widget rendered, or the widget sits in a frame or a closed shadow root the DOM scan can't see. Wait for thechallenges.cloudflare.comiframe first, or passsitekey=. How to find a Cloudflare Turnstile sitekey shows where sites hide it.PeakError: No Peak API key.Neitherapi_key=norPEAK_API_KEYheld a key. Keys start withpk_; the free one comes from the dashboard.PeakError: Peak request failed: ...The HTTPS call toapi.peak.fofailed on your side: DNS, TLS, a firewall, or thetimeout=. Theproxy=argument is forwarded to Peak for the solve and is not used for this call.urllibdoes honour anHTTPS_PROXYvariable in the environment.PeakError:followed by Peak's own reason, orPeak solve failed. Peak answered withsuccess: false. The usual causes are an unknown key, an empty balance, a sitekey that does not belong to the page URL, or aproxy=Peak could not connect through. The Cloudflare Turnstile error codes post covers the widget-side codes (110200, 300030, 600010 and the rest).- The token came back and the form still does nothing.
inject_tokenreturnedFalse: the field is filled, but the site passed a closure toturnstile.render({callback: ...}), and a closure has no global name to call. Submit the form yourself with pydoll, or call the site's handler with the token throughtab.execute_script. cf-turnstile-response is empty and the cf-turnstile-response token explained cover the field. - The submit returns 403 or the form page again. The site refused the token. A token works once and expires 300 seconds after Cloudflare issues it. Pass
proxy=with the browser's own egress so Peak mints the token from the address that submits it. Cloudflare Turnstile 403 walks through the refusal. - The page shows "Just a moment..." and has no widget. That page is the managed 5-second challenge, a separate check from the Turnstile widget. It wants a
cf_clearancecookie, and this package injects widget tokens. Turnstile token vs cookie explains the difference, and the Cloudflare 5-second challenge explained covers the interstitial.
Two longer reads: How to scrape Cloudflare-protected sites without getting blocked and the 2026 Turnstile developer guide.
Related
Other CDP and browser wrappers for the same API: nodriver-turnstile · drissionpage-turnstile · patchright-turnstile · playwright-turnstile · camoufox-turnstile · selenium-turnstile · botasaurus-turnstile · puppeteer-extra-plugin-turnstile · crawlee-turnstile. No browser: cloudscraper-turnstile · turnstile-curl · scrapy-turnstile · scrapling-turnstile. Agents: browser-use-turnstile · crewai-turnstile · langchain-turnstile. Full list in awesome-turnstile-solvers.
cloudflare-turnstile-reversed documents the challenge flow, the widget parameters and the fingerprinting the widget runs before it hands out a token.
Legitimate use
For automation, QA, and scraping public data you are allowed to access. Respect each target's Terms of Service and robots directives, and do not use this for credential stuffing or other abuse. Not affiliated with Cloudflare or the pydoll project.
License
MIT. See LICENSE.
Metadata
Release files for pydoll-turnstile 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydoll_turnstile-0.1.1.tar.gz | 447.0 kB | Without provenance | Details for pydoll_turnstile-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydoll_turnstile-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pydoll_turnstile-0.1.1-py3-none-any.whl |
Total release size: 457.1 kB
Release files / pydoll_turnstile-0.1.1.tar.gz
| Download URL | pydoll_turnstile-0.1.1.tar.gz |
|---|---|
| Size | 447.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7a4b8a061b082c80d6b5d5c8c1a7e543e6f35a4240ed504a95a838074af8be1
|
|
BLAKE2b-256 checksum How to use checksums |
ebfa4a627d05919e11401451152ec4d6ebc688da02ff07fa9b25148957143e70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Release files / pydoll_turnstile-0.1.1-py3-none-any.whl
| Download URL | pydoll_turnstile-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fc15ca12ecebfcf651768a7b19e4bb28960706e51c41b24d4bea081e60c4bc18
|
|
BLAKE2b-256 checksum How to use checksums |
22b127fc501aaf8acb81eb764ed102517dd891536d46c59fcfc1480cf53f7041
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.0
|
Security for pydoll-turnstile 0.1.1
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.