ydpy
Youtube.DownloadPYthon..Clean-room, low-level YouTube download library: multi-client bot-bypass, fast streams, sync & async
- Clean-room reimplementation of yt-dlp's YouTube bot-bypass knowledge — not a fork
- Multi-client innertube requests (visionos / tv / mweb / android_vr) with real visitor data
- Fetches the playable stream list of a single video, nothing else: no playlist expansion, no merging, no post-processing
- Downloads an individual stream as-is into a path or any buffer — no ffmpeg, no filename magic
- Sync and async APIs (async is the same name prefixed with
a) - python >= 3.10
Install
Using uv & pip
pip install ydpy # or: uv add ydpy
Using pyproject.toml
[project]
dependencies = [
"ydpy"
]
Quickstart
import ydpy
video = ydpy.Video("https://www.youtube.com/watch?v=YE7VzlLtp-4")
data = video.fetch() # or: await video.afetch()
for fmt in data.formats:
print(fmt.itag, fmt.mime_type, fmt.width, fmt.height, fmt.bitrate)
# pick the best audio stream
audio = max(
(f for f in data.formats if f.is_audio),
key=lambda f: f.bitrate or 0
)
audio.download("song.webm") # local path
audio.download(open("song.webm", "wb")) # or file-like
import io
buf = io.BytesIO()
audio.download(buf) # or memory buffer
Async download:
import asyncio
async def main():
data = await ydpy.Video("...").afetch()
fmt = next(f for f in data.formats if f.itag == 137)
result = await fmt.adownload("video.mp4")
print(f"{result.bytes_written} bytes")
asyncio.run(main())
Options & progress
You can specify the progress logic and throttle limit or etc. like below:
from ydpy import DownloadOptions
def progress(p):
print(f"{p.downloaded}/{p.total} bytes at {p.speed_bps / 1e6:.1f} MB/s")
fmt.download("out.webm", options=DownloadOptions(
retries=5,
timeout=30.0,
throttled_rate_limit=500_000, # raise ThrottledDownload if sustained slower
progress=progress,
))
How it avoids bot detection & why it is fast
Every request to YouTube is shaped like an official app, not a scraper:
- requests go to the innertube API pretending to be one of several real clients (visionos / an old smart-tv app / mweb / an android-vr app), each with its own device headers and body context;
- the visitor data used for anonymous playback is taken from the actual watch page first, because keyless anonymous API calls are answered with "Sign in to confirm you're not a bot";
- if one client gets rejected, the next client in the chain is tried, and transient bot gates are retried;
- clients that require the newest attestation (web + PO tokens) are simply not used — JS challenge solving and PO token minting are out of scope, and no client in the chain needs them.
Speed is mostly a side effect of not being throttled:
- googlevideo throttles Range-less full-file fetches to ~32 KB/s, so every
download always sends a
Rangeheader (measured 2026-09); - googlevideo also throttles long-lived single connections, so downloads are pulled as sequential 10 MiB range chunks — the same trick yt-dlp uses;
- compression is disabled (
Accept-Encoding: identity) soContent-Lengthstays reliable and no decode CPU is wasted; - one httpx client is reused for the whole download (keep-alive, no repeated TLS handshakes) and reads adapt to the measured throughput;
- failed transfers resume from the last byte instead of restarting.
Benchmarks
Same video, same stream url, same resulting file size — wall time from start to finish (extraction included where applicable). Measured 2026-09-05 from a datacenter VM; numbers vary with network and region.
| format | yt-dlp CLI | ydpy |
|---|---|---|
| audio itag 251 (9.7 MB) | 2.71s (~3.6 MB/s) | 1.37s (~7.1 MB/s) |
| video itag 136 (75 MB, 720p) | 4.26s (~17.6 MB/s) | ~3.3s transfer (19–28 MB/s sustained) |
Before the chunked-range fix the 75 MB video crawled at 0.3 MB/s — exactly the long-connection throttle this library is built to avoid.
Format at a glance
best_video = max(
(f for f in data.formats if f.is_video and not f.is_damaged),
key=lambda f: (f.height or 0, f.bitrate or 0),
)
best_video.itag # 137 — stable identifier
best_video.mime_type # 'video/mp4; codecs="avc1.64001f, mp4a.40.2"'
best_video.width, best_video.height, best_video.fps
best_video.bitrate # bps
best_video.filesize # bytes, when the player response knows it
best_video.has_drm # True → skip it
best_video.protocol # ydpy.StreamingProtocol.HTTPS / HLS / DASH
best_video.download("clip.mp4")
Format is a frozen dataclass — every stream is just data you can inspect,
filter, and hand to download() / adownload().
Why not just use yt-dlp or pytube as a library?
Neither supports async. You can wrap them with asyncio.to_thread, but a
CLI-shaped library occasionally blocks the event loop and is inefficient.
yt-dlp is fundamentally a CLI tool, so its "library" mode is a shell invocation wearing a trench coat. Conveniences that are great for a CLI become surprising side effects for a library:
- a video url that belongs to a playlist downloads the whole playlist
unless you remember the
noplaylistflag; - it merges audio/video with ffmpeg, re-encodes when asked, and applies its own filename rules — control flow you cannot turn off;
- configuration is either shell arguments or a CLI-flavored options dict;
import yt_dlp # the CLI-args shaped library API
ydl_opts = {
"format": "bestaudio/best",
"outtmpl": "song.%(ext)s",
"quiet": True,
"noplaylist": True, # or it silently downloads the playlist
"postprocessors": [{"key": "FFmpegExtractAudio"}],
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(url, download=False)
ydpy takes the opposite route: Video(url).fetch() returns playable streams
and nothing else happens. No downloads you did not ask for, no merging, no
filesystem conventions — the stream is yours to save to a path, a buffer, or
hand to whatever comes next.
Metadata
Release files for ydpy 0.1.0
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 |
|---|---|---|---|---|
| ydpy-0.1.0.tar.gz | 26.7 kB | With provenance | Details for ydpy-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ydpy-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ydpy-0.1.0-py3-none-any.whl |
Total release size: 52.3 kB
Release files / ydpy-0.1.0.tar.gz
| Download URL | ydpy-0.1.0.tar.gz |
|---|---|
| Size | 26.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
714033da2ea9bd9060eb25cbde99cb3f3340d479ce1b8b30be861971f6f0e39e
|
|
BLAKE2b-256 checksum How to use checksums |
5650a393bb09b2f87b240b278ba53db3bbf865c9851e26cd7dfec71eaea30e3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 5, 2026.
Transparency logRelease files / ydpy-0.1.0-py3-none-any.whl
| Download URL | ydpy-0.1.0-py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0711792a8dc8c644b8960968983ab63c6859d3f6a371ebc17b1906d11a607696
|
|
BLAKE2b-256 checksum How to use checksums |
ac938ab393c12e1aaee1b986eb5c8f44edb0a24d57f4dd8f3ae1add59f23dec7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Sep 5, 2026.
Transparency logSecurity for ydpy 0.1.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for ydpy-0.1.0.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 Sep 5, 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.