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

scrapy-turnstile

scrapy-turnstile is a Scrapy downloader middleware that solves Cloudflare Turnstile automatically. When a request hits a Turnstile-protected page, it detects the challenge, solves it through Peak, and re-issues the request with the token so your spider gets the real page.

Why

Scrapy makes plain HTTP requests. It has no JS engine, so a Turnstile-protected site returns a 403 or the "Just a moment..." interstitial instead of the content you asked for. The old scrapy-cloudflare-middleware only handled the legacy IUAM (I'm Under Attack Mode) JS challenge and is unmaintained; it does nothing for Turnstile, which is what Cloudflare now serves. cloudscraper has the same limitation: it can't solve Turnstile.

This middleware routes the Turnstile challenge to Peak, which returns a valid token. 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
  • Pay only for successful solves — from $1 / 1,000
  • 1,000 free solves to start, no card. → Get your free API key · Docs · Pricing

Install

pip install scrapy-turnstile

Quickstart

Add the middleware to your project's settings.py and set your Peak key:

# settings.py
DOWNLOADER_MIDDLEWARES = {
    "scrapy_turnstile.TurnstileMiddleware": 585,
}

PEAK_API_KEY = "pk_your_api_key"   # better: read from an env var
# PEAK_PROXY = "http://user:pass@ip:port"   # optional, routed to Peak

Or per-spider:

import os
import scrapy


class ProtectedSpider(scrapy.Spider):
    name = "protected"
    start_urls = ["https://protected.example.com/"]

    custom_settings = {
        "DOWNLOADER_MIDDLEWARES": {
            "scrapy_turnstile.TurnstileMiddleware": 585,
        },
        "PEAK_API_KEY": os.environ["PEAK_API_KEY"],
    }

    def parse(self, response):
        # The challenge, if any, was already solved upstream.
        yield {"title": response.css("title::text").get()}
export PEAK_API_KEY=pk_your_api_key
scrapy runspider examples/quotes_spider.py

A runnable spider is in examples/quotes_spider.py.

How it works

  1. process_response inspects every response for Turnstile markers (cf-turnstile, the challenges.cloudflare.com/turnstile script, the "Just a moment" interstitial).
  2. On a match it extracts the data-sitekey and the request URL.
  3. It calls Peak: POST https://api.peak.fo/solve with {"task_type": "turnstiletask", "sitekey": ..., "url": ...} and header X-API-Key.
  4. It re-issues the original request with the returned token injected as the cf-turnstile-response form field, and also on request.meta["cf_turnstile_response"] for custom submits.
  5. A meta flag stops the retried request from being re-processed, so there are no loops.

Peak also supports the Cloudflare 5s interstitial via task_type: "cloudflare5stask".

Settings

Setting Default Purpose
PEAK_API_KEY (required) Your Peak key, format pk_....
PEAK_PROXY None Proxy string forwarded to Peak so the solve matches your crawl IP.
PEAK_API_URL https://api.peak.fo/solve Override the solve endpoint.
PEAK_TURNSTILE_FIELD cf-turnstile-response Form field the token is injected into.
PEAK_TURNSTILE_MAX_RETRIES 2 Max solve attempts per request before giving up.
PEAK_APP_ID None Your Peak app ID. When set, you earn a share of every solve made through it — see Earn with Peak.

Earn with Peak

Peak shares revenue with developers who send it solves — the same idea as the big solver SDKs, wired in here:

  • appId — create an app ID in your Peak dashboard (Developer tab) and set PEAK_APP_ID. You earn a share of every solve made through it, including from people running a tool you built on this middleware.
  • Referral — share your referral link (dashboard → Referrals) to earn a share of what anyone you refer tops up.

Both pay out as Peak solve credit; current rates are shown in your dashboard. Set PEAK_APP_ID once and it rides along with every solve — no other code change.

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 scrapy-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 scrapy-turnstile 0.2.0
File Size Uploaded Provenance Actions
scrapy_turnstile-0.2.0.tar.gz 449.2 kB Without provenance Details for scrapy_turnstile-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 459.1 kB

Release files / scrapy_turnstile-0.2.0.tar.gz

Download URL scrapy_turnstile-0.2.0.tar.gz
Size 449.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9426050683227d2319ce4dfaa6cbae3dcc4a08953fc9aea01e19b8f4d60a89d5
BLAKE2b-256 checksum
How to use checksums
65d55d30230d2fb651b9b61b98dd772eee5b600c37dae5611c423901dcff458e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.0

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

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

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