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

selenium-turnstile

selenium-turnstile is a Selenium helper that solves Cloudflare Turnstile by injecting a Peak-solved token, so a protected form or navigation proceeds without a real mouse click.

Why

SeleniumBase's UC-mode click-solve (uc_gui_click_captcha) drives a physical click on the widget, which needs a real display and fails headless on datacenter IPs. That failure mode fills Cloudflare-related SeleniumBase issues (200+ open). undetected-chromedriver has no click-solve at all and gets stuck in the "Just a moment" loop, reloading the interstitial even after the browser has otherwise passed.

This helper skips the click entirely. It reads the sitekey from the DOM, gets a token from Peak, and injects that token as the cf-turnstile-response value plus 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 selenium-turnstile selenium

Quickstart

import os
from selenium import webdriver
from selenium_turnstile import solve_turnstile

os.environ["PEAK_API_KEY"] = "pk_your_api_key"

driver = webdriver.Chrome()
driver.get("https://protected.example/login")

# Reads the sitekey from the page, solves via Peak, injects the token.
token = solve_turnstile(driver)

driver.find_element("css selector", "form").submit()

Works unchanged with a plain Selenium driver, a SeleniumBase Driver, or an undetected-chromedriver Chrome — all three expose the current_url / find_element / execute_script interface the helper uses.

How it works

  1. Read the sitekey. find_element looks for the data-sitekey attribute on the .cf-turnstile widget; if the sitekey is only set through a JS render() call, an execute_script DOM scan finds it.
  2. Solve via Peak. POST https://api.peak.fo/solve with task_type: "turnstiletask", the sitekey, and url=driver.current_url. Pass proxy= to mint the token from your browser's egress IP.
  3. Inject the token. execute_script sets every cf-turnstile-response field, fires input/change events, and calls the widget's data-callback success handler so the form or navigation continues.

API

solve_turnstile(
    driver,               # any Selenium-like WebDriver
    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 driver.current_url
    task_type="turnstiletask",
    timeout=180.0,
    app_id=None,          # optional; earns you a share of each solve
) -> str                  # the injected token

Helpers read_sitekey(driver) and inject_token(driver, token) are exposed for finer control. Peak also supports task_type="cloudflare5stask" for the 5s interstitial challenge.

The API key is read from the PEAK_API_KEY environment variable by default; you can also pass it explicitly. Never hardcode a real key.

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.

solve_turnstile(driver, 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

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.

License

MIT — see LICENSE.

Metadata

Release files for selenium-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 selenium-turnstile 0.2.0
File Size Uploaded Provenance Actions
selenium_turnstile-0.2.0.tar.gz 448.0 kB Without provenance Details for selenium_turnstile-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 456.7 kB

Release files / selenium_turnstile-0.2.0.tar.gz

Download URL selenium_turnstile-0.2.0.tar.gz
Size 448.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b8872d38f5966305f014e868e94547ca78b901844a153c65bd8b5854118ddee9
BLAKE2b-256 checksum
How to use checksums
89092abc9f7f3f1fe4ac9a23361cc01a9e09fefe36ec8737b93b5a9c7dcda878
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Release files / selenium_turnstile-0.2.0-py3-none-any.whl

Download URL selenium_turnstile-0.2.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e10938673dafba4e8f5aa5714ff4cb2a99c86fda9fea6f9083c80b6b7750eb67
BLAKE2b-256 checksum
How to use checksums
bcb50b796ffb6ffdea297dc6498402d5e1b529418a1b8d7debde37767a32cb90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

Security for selenium-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