Skip to main content

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

Project description

ytdown (Python bindings)

Python bindings for the ytdown Rust crate: extract, select, and download media — yt-dlp's core, library only.

Built with maturin / PyO3. The API is synchronous; blocking calls release the GIL and run on a shared tokio runtime.

Install

pip install maturin
maturin develop --release   # from this directory, inside a venv
# or build a wheel:
maturin build --release

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 "..."),
    )

Format selection

VideoInfo.select() returns a chainable FormatSelector mirroring the Rust API:

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)

Playlists, channels, search

Collections are lazy iterators; 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

Merged (split-stream) downloads

Requires ffmpeg on PATH (or pass ffmpeg_binary= to Ytdown):

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

Download options

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 existing partial file
)

Errors

All errors derive from ytdown.YtdownError:

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

from ytdown import YtdownError, FormatNotFoundError

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

Releasing to PyPI

Releases are automated. When a release-please PR is merged on master:

  1. release-please tags the release and bumps the version in both Cargo.toml files (ytdown-py/Cargo.toml is synced via the x-release-please-version annotation).
  2. .github/workflows/release-please.yaml publishes the crate to crates.io, then builds wheels (Linux x86_64, macOS aarch64) via PyO3/maturin-action and publishes them to PyPI.

No sdist is published (maturin can't vendor the path = ".." dependency cleanly). On platforms without a wheel, install from git instead:

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

Authentication uses PyPI Trusted Publishing (OIDC) — no token secret. One-time setup on pypi.org for the ytdown project:

  • Owner: 4thel00z Repository: ytdown
  • Workflow name: release-please.yaml
  • Environment: (leave empty)

License

MIT OR Apache-2.0, same as the Rust crate.

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

File metadata

File hashes

Hashes for ytdown_py-0.3.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a10cc00116a87acfc0668a01890de5a25d94060212f3d37ea0633722d64827e3
MD5 1d9613355860bc6881f655d90a01cdb3
BLAKE2b-256 65993779451b7009f965dc3f87d0ad5df34b7d961316c6320f3ce92d876e77c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for ytdown_py-0.3.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 70a22be5f8b2a8b7268aab003924c0f073afe0716e95e268e4c34cd16f9e85d9
MD5 5c2a6ee0d1eeb169fb9a5cfd669f3e4e
BLAKE2b-256 354e433b947d9efc1e6376dbd4d3a717a83c916eb136de163f3a05b445903bd4

See more details on using hashes here.

Provenance

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