patchright-difz
Patchright Python wrapper with an optional Turnstile helper.
Install
pip install patchright-difz
Sync usage
from patchright_difz.sync_api import sync_playwright
with sync_playwright() as p:
context = p.chromium.launch_persistent_context(
".profile",
headless=False,
channel="chrome",
no_viewport=True,
turnstile=True,
)
page = context.new_page()
page.goto("https://example.com")
Async usage
from patchright_difz.async_api import async_playwright
async with async_playwright() as p:
context = await p.chromium.launch_persistent_context(
".profile",
headless=False,
channel="chrome",
no_viewport=True,
turnstile=True,
)
page = await context.new_page()
await page.goto("https://example.com")
page.evaluate, frame.evaluate, locator evaluate helpers, and handle
evaluate helpers default to the page main world in this wrapper. If you need
Patchright's isolated world for a specific call, pass isolated_context=True.
The Turnstile helper uses Patchright locators for fallback detection, so it can
also pick up challenge candidates rendered inside closed shadow roots.
The hidden cf-turnstile-response field is only used as optional token/data
evidence; active challenge detection prefers visible widgets, iframes, and
clickable candidates.
When headless=True is used without a custom user_agent, the wrapper sets a
normal Chrome user agent before the first request. This applies to
launch_persistent_context, browser.new_context, and browser.new_page.
Set PATCHRIGHT_DIFZ_HEADLESS_USER_AGENT=0 to keep Patchright's default
headless user agent, or set it to a full user-agent string to override the
default.
Configure Turnstile
context = p.chromium.launch_persistent_context(
".profile",
headless=False,
channel="chrome",
no_viewport=True,
turnstile={
"timeout_ms": 5000,
"interval_ms": 750,
"foreground": True,
"click_delay_ms": 35,
"mouse_move_steps": 8,
"logger": print,
},
)
Camel-case option names from the npm package are also accepted:
timeoutMs, intervalMs, maxCandidatesPerSelector, clickDelayMs,
mouseMoveSteps, and waitAfterClickMs.
Manual usage
from patchright_difz.sync_api import check_turnstile, sync_playwright
with sync_playwright() as p:
context = p.chromium.launch_persistent_context(
".profile",
headless=False,
channel="chrome",
no_viewport=True,
)
page = context.new_page()
page.goto("https://example.com")
check_turnstile(page)
Turnstile and Cloudflare data helpers
from patchright_difz.sync_api import (
get_cloudflare_data,
has_turnstile,
is_turnstile_solved,
)
exists = has_turnstile(page)
solved = is_turnstile_solved(page)
data = get_cloudflare_data(page)
print({
"exists": exists,
"solved": solved,
"cookies": data["cloudflare_cookies"],
"clearance": data["clearance_cookie"],
"cleared": data["challenge"]["cleared"],
"document_cookie_names": data["document_cookie_names"],
"tokens": data["turnstile"]["tokens"],
"sitekeys": data["turnstile"]["sitekeys"],
"responses": data["turnstile"]["responses"],
})
Async usage uses the same names with await:
from patchright_difz.async_api import get_cloudflare_data
data = await get_cloudflare_data(page)
get_cloudflare_data reads the current browser context cookies plus visible
page data such as Turnstile response fields, widget sitekey values,
Cloudflare iframe/script URLs, challenge fields, Ray IDs, and
Cloudflare-related local/session storage keys. Pass context and urls when
you only want cookie data for specific URLs:
data = get_cloudflare_data(
context=context,
urls=["https://example.com"],
)
Publish
python scripts/publish.py
The command builds, creates a v<version> git tag, pushes to GitHub, and lets
the GitHub Actions workflow publish to PyPI through Trusted Publishing.
Metadata
Release files for patchright-difz 0.4.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 |
|---|---|---|---|---|
| patchright_difz-0.4.1.tar.gz | 15.8 kB | With provenance | Details for patchright_difz-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| patchright_difz-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for patchright_difz-0.4.1-py3-none-any.whl |
Total release size: 37.6 kB
Release files / patchright_difz-0.4.1.tar.gz
| Download URL | patchright_difz-0.4.1.tar.gz |
|---|---|
| Size | 15.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6973a86c8f07849e9f0dd0361ceb4979cd6ea731923fecf0b4fa43450da7b23
|
|
BLAKE2b-256 checksum How to use checksums |
659d3e5cc7ab5e8a48c70a30e46305a99c372593cf15d0c5323314fd4fdfebf5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logRelease files / patchright_difz-0.4.1-py3-none-any.whl
| Download URL | patchright_difz-0.4.1-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af8fc262b39e9365b0b7c58a2013b2031b55b4b5d1bbbecd3e7c9cf2db0f542e
|
|
BLAKE2b-256 checksum How to use checksums |
c7844eda2c04907c379c634756de1ab5936c8b18dd14c736cf1d85cf04ac51ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logSecurity for patchright-difz 0.4.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for patchright_difz-0.4.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 11, 2026.
Transparency logA 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.