Fast, efficient batch YouTube metadata fetching with Redis caching.
Project description
YouTube Details
A standalone, asynchronous Python library to efficiently fetch metadata from YouTube URLs. It supports batch fetching and individual video caching with Redis.
Features
- ⚡ Asynchronous: Built with
httpxfor high-performance async requests. - 📦 Batch Fetching: Automatically batches requests (50 per call) to stay within API limits.
- 🚀 Redis Caching: Optional Redis support to cache metadata and reduce API costs.
- 🔗 Smart Extraction: Supports multiple YouTube URL formats (watch, shorts, embed, youtu.be).
- 🛠️ Lightweight: Minimal dependencies, easy to integrate.
Installation
pip install yt-details
To include Redis support:
pip install "yt-details[redis]"
Quick Start
Basic Usage
import asyncio
from yt_details import YouTubeService
async def main():
service = YouTubeService(api_key="YOUR_API_KEY")
# Fetch a single video
details = await service.get_video_details("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(f"Title: {details['title']}")
if __name__ == "__main__":
asyncio.run(main())
With Redis Caching
import redis.asyncio as redis
from yt_details import YouTubeService
# Initialize async Redis client
redis_client = redis.from_url("redis://localhost:6379")
# Service will now cache results for 24 hours (86400 seconds)
service = YouTubeService(
api_key="YOUR_API_KEY",
redis_client=redis_client,
cache_ttl=86400
)
Batch Fetching
The service handles batching efficiently:
urls = [
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
"https://youtu.be/kJQP7kiw5Fk",
# ... more URLs
]
results = await service.get_videos_details_batch(urls)
for url, data in results.items():
if "error" not in data:
print(f"{data['title']} - {data['views_formatted']} views")
License
MIT
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
yt_details-0.1.3.tar.gz
(6.5 kB
view details)
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_details-0.1.3.tar.gz.
File metadata
- Download URL: yt_details-0.1.3.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a071a321764d4492ca82ed1ec054518829c5773aa9bfa44cc56cebeddeb045bd
|
|
| MD5 |
558557e9af61bdbb662b3f758cdea783
|
|
| BLAKE2b-256 |
e1c6e66d9bc156ca36320a07f181313db68dea7568d5ff7c80f1797c649e1ae1
|
File details
Details for the file yt_details-0.1.3-py3-none-any.whl.
File metadata
- Download URL: yt_details-0.1.3-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c34b5a1491689b0e94de16a9ba4338e06cc8774c756a84af29c3bf64b1cf4f1
|
|
| MD5 |
4a2cabc8f5e70ac26ae9d4cfd4cabcdb
|
|
| BLAKE2b-256 |
97b688873324cc26a84ac61f7b9a31d5aa3106ad41774adf81305de79c03f2ef
|