Python client for yt-download-api — download YouTube videos via HTTP from any script or bot.
Project description
yt-download-client
Python client for yt-download-api.
Download YouTube videos from any Python script, Discord bot, or Telegram bot — without dealing with HTTP, polling, or error handling yourself.
pip install yt-download-client
Requirements
A running instance of yt-download-api. Deploy your own in one click or run it locally.
Quick start
from yt_download_client import YTDownloadClient
client = YTDownloadClient(
base_url="https://your-api.onrender.com",
api_key="YOUR_KEY",
)
path = client.download("https://youtu.be/dQw4w9WgXcQ")
print(f"Saved to {path}")
Usage
One-liner download
path = client.download(
url="https://youtu.be/dQw4w9WgXcQ",
format="mp4",
quality="720p",
output="video.mp4",
)
Supported formats: mp4, mp3, webm
Supported qualities: best, 1080p, 720p, 480p, 360p, audio_only
With progress tracking
from yt_download_client import Job
def on_progress(job: Job):
if job.status == "progress" and job.progress:
downloaded = job.progress.get("downloaded_bytes", 0)
total = job.progress.get("total_bytes", 0)
if total:
pct = round(downloaded / total * 100)
print(f"{pct}%", end="\r")
path = client.download(
"https://youtu.be/dQw4w9WgXcQ",
on_progress=on_progress,
)
Step by step
For more control — submit, wait, and fetch separately:
# Submit and get a job ID immediately
job = client.submit("https://youtu.be/dQw4w9WgXcQ", format="mp3", quality="audio_only")
print(f"Job submitted: {job.id}")
# Wait until done (blocks, polls every 5s)
job = client.wait(job.id, poll_interval=5, timeout=300)
# Download the file
path = client.fetch(job.id, output="song.mp3")
print(f"Saved to {path}")
Get video info before downloading
info = client.info("https://youtu.be/dQw4w9WgXcQ")
print(info.title)
print(info.duration_formatted) # "03:33"
print(info.uploader)
for fmt in info.formats:
print(fmt["resolution"], fmt["ext"])
Discord bot example
import discord
from yt_download_client import YTDownloadClient, JobFailedError
client = YTDownloadClient(base_url="https://your-api.onrender.com", api_key="YOUR_KEY")
bot = discord.Client(intents=discord.Intents.default())
@bot.event
async def on_message(message):
if message.content.startswith("!download "):
url = message.content.split(" ", 1)[1]
await message.channel.send("Downloading...")
try:
path = client.download(url, format="mp4", quality="720p")
await message.channel.send(file=discord.File(str(path)))
except JobFailedError as e:
await message.channel.send(f"Failed: {e}")
Error handling
from yt_download_client import (
YTDownloadClient,
AuthenticationError,
RateLimitError,
JobFailedError,
JobTimeoutError,
ServerBusyError,
YTDownloadError,
)
try:
client.download("https://youtu.be/dQw4w9WgXcQ")
except AuthenticationError:
print("Bad API key")
except RateLimitError as e:
print(f"Slow down: {e}")
except JobFailedError as e:
print(f"Download failed: {e}")
except JobTimeoutError:
print("Took too long")
except ServerBusyError:
print("Server is busy, retry later")
except YTDownloadError as e:
print(f"Something went wrong: {e}")
API reference
YTDownloadClient(base_url, api_key, timeout=30)
| Method | Description |
|---|---|
download(url, format, quality, output, poll_interval, timeout, on_progress) |
Full flow in one call |
submit(url, format, quality, webhook_url) → Job |
Submit a job |
wait(job_id, poll_interval, timeout, on_progress) → Job |
Wait for completion |
fetch(job_id, output) → Path |
Download the output file |
status(job_id) → Job |
Get current job status |
info(url) → VideoInfo |
Fetch video metadata |
health() → dict |
Check API health |
delete(job_id) → dict |
Delete a file from the server |
Job
| Attribute | Type | Description |
|---|---|---|
id |
str |
Job ID |
status |
str |
pending, started, progress, post_processing, success, failure |
progress |
dict |
Progress info (speed, ETA, bytes) |
download_url |
str |
Relative download path when done |
error |
str |
Error message on failure |
done |
bool |
True if success or failure |
successful |
bool |
True if success |
VideoInfo
| Attribute | Type | Description |
|---|---|---|
title |
str |
Video title |
duration |
int |
Duration in seconds |
duration_formatted |
str |
Human-readable duration (03:33) |
uploader |
str |
Channel name |
thumbnail |
str |
Thumbnail URL |
formats |
list |
Available formats |
filesize_approx |
int |
Approximate file size in bytes |
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yt_download_client-1.0.1.tar.gz.
File metadata
- Download URL: yt_download_client-1.0.1.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.1"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.1","system":{"name":"Linux","release":"6.8.0-1052-azure"}} HTTPX2/2.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cf4bdfa8410fc4922696b6e5268e1061fdde2d5790805ed4b9b158b8526ac18
|
|
| MD5 |
9b3cf5180d6464fd91e0f800ae18c06d
|
|
| BLAKE2b-256 |
4b12964dcb330c2d42b3b9c7c948242a20ea876a05a90d31acf0a53b7b6e3644
|
File details
Details for the file yt_download_client-1.0.1-py3-none-any.whl.
File metadata
- Download URL: yt_download_client-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"x86_64","distro":{"id":"noble","libc":{"lib":"glibc","version":"2.39"},"name":"Ubuntu","version":"24.04"},"implementation":{"name":"CPython","version":"3.12.1"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 3.0.13 30 Jan 2024","python":"3.12.1","system":{"name":"Linux","release":"6.8.0-1052-azure"}} HTTPX2/2.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70f27ecab8e30cb917afdaded3820a4618fe1e60dc8eced4511ef6cdb15a7f2e
|
|
| MD5 |
98e0e6664a8fb4c30fe19740956cd362
|
|
| BLAKE2b-256 |
3dff29e39ef6daa09871aac861bbdb0d1bffd104a82d29cf258e9212424e2075
|