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.7.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.7.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.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for ytdown_py-0.7.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d76b6cc9a622273aa872b4ef7d1ad2ada6f12cfdcaee9717f488c3babb7ef93
MD5 99b40634951af05c1f164c43880c840d
BLAKE2b-256 d7f063c357559c098708ec3e43613eb3eeafb66dc2f74496220a3e3ccaee3f59

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytdown_py-0.7.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.7.0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ytdown_py-0.7.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4074d5cb357c0756f035b64dcc14141c54f00adc9a758a5b5a2d76fd57b60b8a
MD5 546f1b4dca1023aedd6f236ece1348ff
BLAKE2b-256 7ee48e944ba227c38c6b07580b0b392ae62a525d6a230b60541779d6e70a88d1

See more details on using hashes here.

Provenance

The following attestation bundles were made for ytdown_py-0.7.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