Skip to main content
Peak — solve Cloudflare Turnstile & the 5s challenge in ~1s

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 just works.

Powered by Peak

This package uses Peak to solve Turnstile.

  • Solve Cloudflare Turnstile & the 5s challenge in about a second
  • $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 task_type: "turnstiletask", the sitekey, url: page.url, and your optional proxy.
  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.

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.0

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.0
File Size Uploaded Provenance Actions
playwright_turnstile-0.2.0.tar.gz 9.6 kB Without provenance Details for playwright_turnstile-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 18.3 kB

Release files / playwright_turnstile-0.2.0.tar.gz

Download URL playwright_turnstile-0.2.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
5fe29f5fada34796db757f8a75215b0edcfb47d65d675e278a14c18323f0ef68
BLAKE2b-256 checksum
How to use checksums
175370f5e216c40ffc28bc72567bf6d7dcbe7c70446cdcdbc80efc3e72951092
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.0-py3-none-any.whl

Download URL playwright_turnstile-0.2.0-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b46ccaf27fe2ec22a23fa05e81f51e77cfbd1196280480a59ead349e7b769cbc
BLAKE2b-256 checksum
How to use checksums
ee7875bf0bdadd4bbdce1c859b5dc9d736e160a6dfef80bc5b920565a54cc70d
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.0

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