Skip to main content

ProxyHat residential proxies for yt-dlp — unblock geo-restricted videos through residential IPs, with sticky sessions and rotation.

Project description

yt-dlp-proxyhat

Download videos with yt-dlp through ProxyHat residential proxies — unblock region-locked videos by fetching them through a residential IP in the right country, with a sticky IP per download plus rotation and socks5.

CI Compatible with yt-dlp latest PyPI License: MIT

Why

Lots of videos are geo-restricted — available in one country and blocked everywhere else. yt-dlp can route through a proxy, but only if you have a residential exit IP in the right place. This package plugs ProxyHat's residential IPs (50M+ across 148+ countries) into yt-dlp's first-class proxy option: pick a country and the whole download — manifest and every fragment — comes from a real residential IP there, so the site serves the video instead of a geo-block. No fork, no boilerplate.

Install

pip install yt-dlp-proxyhat

yt-dlp is a peer dependency — bring your own version. proxyhat_proxy_url() and proxyhat_ydl_opts() work on their own; ProxyHatYoutubeDL needs yt-dlp installed:

pip install yt-dlp-proxyhat yt-dlp

Quick start

CLI

yt-dlp takes one proxy per run via --proxy URL. Generate the URL and hand it over:

yt-dlp --proxy "$(PROXYHAT_API_KEY=ph_xxx python -m yt_dlp_proxyhat --country us)" \
  "https://www.youtube.com/watch?v=..."

(Or wire the URL however you like — see examples/cli.py.)

Python API

from yt_dlp_proxyhat import ProxyHatYoutubeDL

# An API key auto-selects an active residential sub-user:
with ProxyHatYoutubeDL({"format": "best"}, country="us") as ydl:  # sticky US IP for the whole run
    ydl.download(["https://www.youtube.com/watch?v=..."])

Get an API key at proxyhat.com.

Already building your own YoutubeDL? Grab the opts dict or the raw URL:

import yt_dlp
from yt_dlp_proxyhat import proxyhat_ydl_opts, proxyhat_proxy_url

# Merge the proxy into your own options:
opts = proxyhat_ydl_opts(country="gb", base={"format": "bestvideo+bestaudio", "outtmpl": "%(title)s.%(ext)s"})
with yt_dlp.YoutubeDL(opts) as ydl:
    ydl.download(["https://www.youtube.com/watch?v=..."])

# ...or just the URL string:
url = proxyhat_proxy_url(country="jp", sticky="1h")
# -> "http://<user>-country-jp-sid-<id>-ttl-1h:<pass>@gate.proxyhat.com:8080"

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

Every option is accepted by proxyhat_proxy_url, proxyhat_ydl_opts and ProxyHatYoutubeDL:

ProxyHatYoutubeDL(
    {"format": "best"},  # your normal yt-dlp params dict (first positional arg)
    protocol="http",     # or "socks5"
    country="us",        # ISO code or "any" (default) — set this to unblock geo-locked video
    region="california",
    city="new_york",
    filter="high",       # AI IP-quality tier
    sticky="30m",        # session lifetime (default); sticky=False rotates per run
    auto_init=False,     # any extra kwarg is forwarded to yt_dlp.YoutubeDL
)

Geo-unblocking

This is the main use. Set country to a region the video is available in, and yt-dlp fetches it through a residential IP there:

# A video only playable in Japan:
with ProxyHatYoutubeDL(country="jp") as ydl:
    ydl.download(["https://www.youtube.com/watch?v=..."])

yt-dlp also has its own geo_bypass (spoofs X-Forwarded-For), but many sites ignore that header — a real residential exit IP in the target country is what actually works, and it's what a proxy gives you.

Sticky IP per run (default) vs rotation

yt-dlp uses one proxy for the whole run, so stickiness here is about that run, and "rotation" means a fresh IP on the next run/connection — never mid-download. A download pulls a manifest and then many fragments; they must all come from the same country, so this package is sticky by default: one residential IP is pinned for the run (sticky="30m").

Want a fresh IP on the next run instead (e.g. a loop over many URLs, each from a new IP)? Turn stickiness off — mint a new proxy per run:

from yt_dlp_proxyhat import ProxyHatYoutubeDL

for url in urls:
    with ProxyHatYoutubeDL(country="us", sticky=False) as ydl:  # fresh residential IP each run
        ydl.download([url])

Set a custom lifetime with sticky="2h".

How it works

proxyhat_proxy_url(...) resolves your gateway credentials (via the official proxyhat SDK — an API key auto-picks an active sub-user, or pass username/password), then builds the proxy URL: the host is the ProxyHat gateway (gate.proxyhat.com:8080, or :1080 for SOCKS5) and the username carries ProxyHat's targeting grammar (<user>-country-us-sid-<id>-ttl-30m). proxyhat_ydl_opts(...) drops that URL into yt-dlp's proxy params key (merging your base options); ProxyHatYoutubeDL is a thin yt_dlp.YoutubeDL subclass that does it for you (yt-dlp is imported lazily, so importing this package is cheap and needs no yt-dlp install). A sticky username (with a session id) pins one residential IP for the download; a rotating one (no session id) makes the gateway hand out a fresh IP on the next connection.

License

MIT © ProxyHat

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yt_dlp_proxyhat-0.1.0.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yt_dlp_proxyhat-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file yt_dlp_proxyhat-0.1.0.tar.gz.

File metadata

  • Download URL: yt_dlp_proxyhat-0.1.0.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yt_dlp_proxyhat-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6223679eec6e8119718658d345da9de3982c7a699a7fda5691fc6911941b0b4f
MD5 c5eff173b33f24c21583183c4369285e
BLAKE2b-256 c52438b9eb8bfad104347499db198dc79ec0904608ebe272e5dc330dbbb25b90

See more details on using hashes here.

Provenance

The following attestation bundles were made for yt_dlp_proxyhat-0.1.0.tar.gz:

Publisher: ci.yml on ProxyHatCom/yt-dlp-proxyhat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yt_dlp_proxyhat-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: yt_dlp_proxyhat-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yt_dlp_proxyhat-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7b9ce1eb45bb3f930d675cd23265ac51f7d7d2dc5d3f989aa2c1b2874ca612e2
MD5 0330586c539761c42dac1b316734401b
BLAKE2b-256 4016f6e9f1e1c4eabe7e74338102887bad00ce338b7cf2c1ce8669975a090dd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for yt_dlp_proxyhat-0.1.0-py3-none-any.whl:

Publisher: ci.yml on ProxyHatCom/yt-dlp-proxyhat

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page