Skip to main content

crawl4ai-proxyhat

Route Crawl4AI crawls through ProxyHat residential proxies — rotating IPs, geo-targeting, and sticky sessions mapped to Crawl4AI's own proxy rotation strategy.

CI Compatible with Crawl4AI latest PyPI License: MIT

Why

Crawling at scale from datacenter IPs gets you blocked and rate-limited. This package plugs ProxyHat's residential IPs (50M+ across 148+ countries) into Crawl4AI through its first-class ProxyConfig and ProxyRotationStrategy APIs — a fresh IP per browser context by default, and one pinned IP per Crawl4AI proxy session when you want it. No fork, no boilerplate.

Install

pip install crawl4ai-proxyhat

Crawl4AI itself is an optional dependency — bring your own version (crawl4ai>=0.5), or install it alongside:

pip install "crawl4ai-proxyhat[crawl4ai]"

Quick start

import asyncio
from crawl4ai import AsyncWebCrawler, CrawlerRunConfig
from crawl4ai_proxyhat import ProxyHatRotationStrategy

async def main():
    # An API key auto-selects an active residential sub-user:
    strategy = ProxyHatRotationStrategy.from_credentials(
        api_key="ph_your_api_key",
        country="us",
    )
    run_config = CrawlerRunConfig(proxy_rotation_strategy=strategy)

    async with AsyncWebCrawler() as crawler:
        result = await crawler.arun("https://httpbin.org/ip", config=run_config)
        print(result.html)

asyncio.run(main())

Get an API key at proxyhat.com.

Prefer a single fixed proxy? Use the convenience helper and hand it to BrowserConfig or CrawlerRunConfig:

from crawl4ai import AsyncWebCrawler, BrowserConfig, CrawlerRunConfig
from crawl4ai_proxyhat import proxyhat_proxy_config

proxy = proxyhat_proxy_config(api_key="ph_your_api_key", country="us")

async with AsyncWebCrawler(config=BrowserConfig(proxy_config=proxy)) as crawler:
    result = await crawler.arun("https://example.com", config=CrawlerRunConfig())

Credentials

Pass them explicitly or via environment variables — options win over env:

Option Env var Notes
api_key PROXYHAT_API_KEY Auto-selects an active sub-user with remaining traffic
sub_user PROXYHAT_SUBUSER Pick a specific sub-user by uuid or name (with an API key)
username PROXYHAT_USERNAME Explicit gateway proxy_username (skips the API)
password PROXYHAT_PASSWORD Explicit gateway proxy_password

Targeting

strategy = ProxyHatRotationStrategy.from_credentials(
    api_key="ph_your_api_key",
    protocol="http",       # or "socks5"
    country="us",          # ISO code or "any" (default)
    region="california",
    city="new_york",
    filter="high",         # AI IP-quality tier
    sticky_ttl="30m",      # sticky-session lifetime (default "30m")
)

The same knobs (country, region, city, filter, plus sticky) are accepted by proxyhat_proxy_config(...).

How it works

Crawl4AI picks a proxy per request from the CrawlerRunConfig you pass to arun / arun_many:

  • Rotating (default). With no proxy_session_id, Crawl4AI calls get_next_proxy(). We return a ProxyHat gateway ProxyConfig with a stable targeting username and no sticky token, so the gateway hands out a fresh residential IP for each new browser context.
  • Sticky (pinned IP). Set a proxy_session_id and Crawl4AI calls get_proxy_for_session(session_id, ttl). The first call mints one ProxyHat sticky session (a -sid-…-ttl-… gateway username) and caches it, so every request sharing that session id exits from the same IP until the TTL lapses or you release the session. Crawl4AI's proxy_session_ttl (seconds) maps to ProxyHat's sticky TTL; without one, sticky_ttl applies.
# Pin one residential IP for a logical user session:
run_config = CrawlerRunConfig(
    proxy_rotation_strategy=strategy,
    proxy_session_id="user-42",
    proxy_session_ttl=1800,   # 30 minutes
)

Targeting and stickiness are both expressed in the gateway username using ProxyHat's targeting grammar (built by the official proxyhat SDK); the sub-user password and gateway host/port stay constant. A single ProxyHat gateway fronts the whole residential pool, so there is no external proxy list to round-robin over — add_proxies() is a no-op kept for interface compatibility.

License

MIT © ProxyHat

Metadata

Release files for crawl4ai-proxyhat 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crawl4ai-proxyhat 0.1.1
File Size Uploaded
crawl4ai_proxyhat-0.1.1.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for crawl4ai-proxyhat 0.1.1
File Interpreter ABI Platform
crawl4ai_proxyhat-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.1 kB

Release files / crawl4ai_proxyhat-0.1.1.tar.gz

Download URL crawl4ai_proxyhat-0.1.1.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5d81e118c19e91129b96e388ff4d3734b7b4a19076015491537bcab15b2df051
BLAKE2b-256 checksum
How to use checksums
41f150d8fb10394a3fb3ee9d9fd1ca5b7e0d72b3987b3e880df79cad6eb235da
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 Jul 14, 2026.

Transparency log

Release files / crawl4ai_proxyhat-0.1.1-py3-none-any.whl

Download URL crawl4ai_proxyhat-0.1.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
014994b625c30ccb43b0dc4bed7517371bcd05977cabb8a556ef88786c1d985f
BLAKE2b-256 checksum
How to use checksums
3d7b464287f4a678537c26ef24a919f8f56d2d71082bf766c1850e9197168b18
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 Jul 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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