Skip to main content
Peak: solve Cloudflare Turnstile and the 5s challenge from headless browsers and datacenter IPs

playwright-turnstile

playwright-turnstile is a Playwright helper that solves Cloudflare Turnstile for you: it reads the sitekey off the page, gets a token from Peak, and injects it so your submit or navigation goes through.

from playwright_turnstile import solve_turnstile

token = await solve_turnstile(page, api_key="pk_your_api_key")

Why

playwright-stealth is a proof of concept. Even with a patched, real browser, interactive Turnstile still fails from headless and datacenter environments: the widget scores the session, sees a datacenter IP with no trusted history, and holds you at the "Verifying..." spinner or an endless challenge. Clicking the checkbox harder does not help, because the token you need is issued by Cloudflare's risk engine, not by the click.

So this package does not click. It reads the Turnstile sitekey from the DOM, hands it to Peak, and injects the returned token into cf-turnstile-response while firing the widget's success callback. When your setup gets blocked, drop in a Peak API key and it works.

Powered by Peak

This package uses Peak to solve Turnstile.

  • Solves Cloudflare Turnstile and the 5s challenge, headless, from datacenter IPs
  • $0.90 per 1,000 successful Turnstile solves, down to $0.35 at volume
  • 1,000 free solves to start, no card.

→ Get your free API key · Docs · Pricing

Install

pip install playwright-turnstile playwright
playwright install chromium

The core package has no runtime dependencies; playwright is the one you drive it with.

Quickstart

import asyncio
from playwright.async_api import async_playwright
from playwright_turnstile import solve_turnstile

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(headless=True)
        page = await browser.new_page()
        await page.goto("https://protected.example/login")

        # Reads the sitekey, solves via Peak, injects the token.
        await solve_turnstile(page, api_key="pk_your_api_key")

        await page.click("button[type=submit]")
        await page.wait_for_load_state("networkidle")
        await browser.close()

asyncio.run(main())

Set your key once and let it read from the environment:

export PEAK_API_KEY=pk_your_api_key   # Windows: set PEAK_API_KEY=pk_your_api_key
await solve_turnstile(page)  # picks up PEAK_API_KEY

API

await solve_turnstile(page, api_key=None, proxy=None, sitekey=None, timeout=180.0)

Solve the Turnstile challenge on a Playwright async Page. Returns the token (also injected into the page).

  • page: a Playwright async Page on a Turnstile-protected URL.
  • api_key: Peak key (pk_...). Falls back to the PEAK_API_KEY env var.
  • proxy: optional proxy passed to Peak, e.g. http://user:pass@ip:port. Use the same egress IP as your browser so the token matches the session.
  • sitekey: override the sitekey instead of reading it from the DOM.
  • timeout: seconds to wait for Peak.
  • app_id: optional Peak app ID. Falls back to the PEAK_APP_ID env var. Earns you a share of each solve, see Earn with your app ID.

solve_turnstile_sync(page, ...)

Same signature, for Playwright's sync API (sync_playwright). Blocking.

from playwright_turnstile import solve_turnstile_sync

with sync_playwright() as p:
    page = p.chromium.launch().new_page()
    page.goto("https://protected.example/login")
    solve_turnstile_sync(page, api_key="pk_your_api_key")

How it works

  1. Reads the sitekey from the widget (.cf-turnstile[data-sitekey], any [data-sitekey], or the challenges.cloudflare.com iframe src) via query_selector / evaluate.
  2. Calls Peak POST https://api.peak.fo/solve with the sitekey and url: page.url. With a proxy it sends task_type: "turnstiletask" and Peak solves through your proxy. With no proxy it sends task_type: "turnstiletaskproxyless" and Peak solves from its own IPs. Both cost the same.
  3. Injects the returned token into every cf-turnstile-response field (creating a hidden input if the widget has not yet) and invokes the widget's data-callback, so your form submit or navigation proceeds.

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

Earn with your app ID

Pass app_id="app_your_id" (or set the PEAK_APP_ID environment variable) to earn 5% of every solve routed through this package, paid as Peak solve credit. It is optional and does not change whether a solve succeeds or how fast it returns.

await solve_turnstile(page, app_id="app_your_id")   # or: export PEAK_APP_ID=app_your_id

Create an app id at peak.fo/dashboard/developer; details at peak.fo/earn.

Troubleshooting

The failures people report with this package come down to the same five. Each has a longer write-up on the Peak blog.

  • PeakError: No Turnstile sitekey found on the page. The widget had not rendered when solve_turnstile ran, or the site loads it from a script the DOM selectors never see. Wait for .cf-turnstile or the challenges.cloudflare.com iframe before you call it, or pass sitekey= by hand. How to find a Cloudflare Turnstile sitekey covers the DevTools route and the places sites hide it.
  • PeakError: Peak HTTP 400: {"success":false,"error":"Missing required fields: sitekey, url, proxy", ...}. You are on 0.2.1 or older and called solve_turnstile with no proxy. Those versions sent the proxied task every time, and Peak's API refuses that task when the proxy is absent. Run pip install -U playwright-turnstile: 0.2.2 sends the proxyless task when you pass no proxy.
  • cf-turnstile-response is empty when your own code reads it. You read the field before the solve returned, or the page re-rendered the widget after injection and wiped the hidden input. Await solve_turnstile, then submit in the same step. cf-turnstile-response is empty lists the causes in order, and the cf-turnstile-response token explained covers what the server does with the token once it arrives.
  • The page still answers 403 after the token lands. That is a different wall. A Turnstile token satisfies a widget on a form. A 403 interstitial wants a cf_clearance cookie from the 5-second challenge, which is Peak's cloudflare5stask, not this package. Turnstile token vs cookie explains which one you need, and Cloudflare Turnstile 403 walks through the fix.
  • The widget shows an error code such as 110200, 300030 or 600010. Cloudflare Turnstile error codes groups them by what failed, from a domain missing on the sitekey's allowlist to a challenge run that died inside the iframe.

The full walkthrough for this stack, including why the proxy you pass to Peak should match the browser's egress IP, is Turnstile in Playwright and Puppeteer (also on Hashnode).

Same pattern for other stacks: patchright-turnstile · camoufox-turnstile · puppeteer-extra-plugin-turnstile · selenium-turnstile · nodriver-turnstile · crawlee-turnstile · browser-use-turnstile · scrapy-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

Built for automation, QA, and scraping public data. Respect each target's Terms of Service and robots.txt, and do not use it for credential-stuffing or other abuse. You are responsible for how you use it.

License

MIT, see LICENSE.

Metadata

Release files for playwright-turnstile 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 playwright-turnstile 0.2.2
File Size Uploaded Provenance Actions
playwright_turnstile-0.2.2.tar.gz 10.9 kB Without provenance Details for playwright_turnstile-0.2.2.tar.gz

Built distribution (wheel)

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

Total release size: 20.9 kB

Release files / playwright_turnstile-0.2.2.tar.gz

Download URL playwright_turnstile-0.2.2.tar.gz
Size 10.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f1be6fe6812bd8a444bd72d6024c88ea6330804f68a942060ae7d475187ded06
BLAKE2b-256 checksum
How to use checksums
24ad569fa4f9c6c7440678e77981665bf32e4835624c769526fa9aa16ee2276b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

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

Download URL playwright_turnstile-0.2.2-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16789941082df9afe05ec879b5432d62fa3ad46ea93e098732b28882bc943c6c
BLAKE2b-256 checksum
How to use checksums
2f3af773510983dc6df49a1ff2e3aa9f847e1696508d5ccd7f11de1074ab3690
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for playwright-turnstile 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