Skip to main content

Python bindings for ytdown: extract, select, and download media (yt-dlp core in Rust).

Project description

ytdown-py

Resolve media URLs into metadata and formats, pick a format, download it. Powered by the ytdown Rust crate, so it is fast and dependency-free. The API is synchronous and releases the GIL during network and disk I/O, so it plays well with threads.

Install

uv add ytdown-py

On platforms without a prebuilt wheel (anything other than Linux x86_64 and macOS arm64), install from source instead. This needs a Rust toolchain:

uv add "git+https://github.com/4thel00z/ytdown#subdirectory=ytdown-py"

Quickstart

from ytdown import Ytdown, VideoInfo

yt = Ytdown()
info = yt.resolve("https://youtu.be/dQw4w9WgXcQ")

if isinstance(info, VideoInfo):
    fmt = info.select().best_progressive()
    yt.download(
        fmt,
        "out.mp4",
        progress=lambda p: print(f"{p.percent():.1f}%" if p.percent() else "..."),
    )

Ytdown() holds a shared HTTP client. Create it once and reuse it across resolves and downloads. It accepts two optional keyword arguments:

yt = Ytdown(user_agent="my-app/1.0", ffmpeg_binary="/opt/ffmpeg/bin/ffmpeg")

Inspecting a video

resolve() returns a VideoInfo for single videos:

info.id           # "dQw4w9WgXcQ"
info.title        # "Rick Astley - Never Gonna Give You Up ..."
info.duration     # 213.0 (seconds)
info.uploader     # "Rick Astley"
info.view_count   # 1234567
info.upload_date  # "20091025" (YYYYMMDD)
info.thumbnails   # [Thumbnail(url=..., width=..., height=...), ...]
info.formats      # [Format(...), ...]
info.to_json()    # full metadata as a JSON string

Format selection

VideoInfo.select() returns a chainable FormatSelector. Filters narrow the set, terminal methods pick a format:

fmt = info.select().progressive().max_height(720).best_video()
audio = info.select().audio_only().best_audio()
video, audio = info.select().best_video_audio()
fmt = info.select().by_itag(22)
worst = info.select().worst()

Filters: progressive(), video_only(), audio_only(), max_height(h), container("mp4"), vcodec_starts_with("avc1").

Terminals: best_progressive(), best_video(), best_audio(), best_video_audio(), worst(), by_itag(itag).

Each Format exposes itag, url, kind ("progressive", "video_only", "audio_only"), container, filesize, bitrate, and nested video/audio stream details.

Downloading

yt.download(
    fmt,
    "out.mp4",
    progress=on_progress,        # callable(Progress) -> None
    concurrency=4,               # parallel range-chunk connections
    chunk_size=10 * 1024 * 1024, # bytes per chunk (parallel mode)
    retries=3,
    resume=True,                 # resume from an existing partial file
)

The progress callback receives Progress snapshots with bytes_downloaded, total_bytes, speed_bps, eta, and percent().

Merged downloads

The highest quality streams are usually split into separate video and audio. Download both and mux them with ffmpeg (must be on PATH, or pass ffmpeg_binary= to Ytdown):

video, audio = info.select().best_video_audio()
yt.download_merged(video, audio, "out.mp4")

Playlists, channels, search

resolve() returns a Collection for playlists, channels, and ytsearch: queries. Collections are lazy iterators; further pages are fetched on demand:

from ytdown import Collection

result = yt.resolve("ytsearch:rust programming")
if isinstance(result, Collection):
    for entry in result:
        print(entry.id, entry.title)
        full = yt.resolve(entry.url)  # resolve the full item
        break

Errors

All errors derive from ytdown.YtdownError:

UnsupportedUrlError, NetworkError, ExtractionError, UnavailableError, CipherError, FormatNotFoundError, IoError, PostprocessError.

from ytdown import FormatNotFoundError

try:
    fmt = info.select().audio_only().by_itag(9999)
except FormatNotFoundError:
    ...

License

MIT OR Apache-2.0.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

ytdown_py-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.6 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

ytdown_py-0.4.0-cp310-abi3-macosx_11_0_arm64.whl (6.0 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file ytdown_py-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ytdown_py-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d7550ec2cbca0106b04437beb9a42e687fb6fedb37f5f917616e1135418190b3
MD5 098f3dfd64d4625333dc7e8a153ef8fb
BLAKE2b-256 7e7a19f5aa247d78f6e7c0417ab3f815eea036aa6c52fa8d2706ec338c4b5e14

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytdown_py-0.4.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-please.yaml on 4thel00z/ytdown

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

File details

Details for the file ytdown_py-0.4.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ytdown_py-0.4.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4143d516da7f72b09866f785b9b5a19ecf73d7cd3ec0c3a04c5c66e3c7018abd
MD5 504b8486b8b7660ef7755b021bffcf1d
BLAKE2b-256 6aa57fa6b79dffc99f9a670b9f9145309a3dd33242c4fade2e6a98be2092692e

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytdown_py-0.4.0-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release-please.yaml on 4thel00z/ytdown

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