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.2.tar.gz
(6.4 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.2.tar.gz.
File metadata
- Download URL: yt_details-0.1.2.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59a60e8edd4dfa5924f4ebf43c31d698561d06bb66a5a8660b1822fa12caed6b
|
|
| MD5 |
2e17ce8c93f25ef38d3e9bb5bab5d367
|
|
| BLAKE2b-256 |
d43e5c14581558fdea627ef530b15e85e5d0bbfdf63817e992523bc0ad0001c8
|
File details
Details for the file yt_details-0.1.2-py3-none-any.whl.
File metadata
- Download URL: yt_details-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.5 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 |
49a697904bf25f9b0a12b4b4ca7cd4e3a8c2d1e90561142d1de6d2a8c802fe7a
|
|
| MD5 |
9b2b56f7760176d3e90439f6b41b7273
|
|
| BLAKE2b-256 |
ed89875c3f235c206133aeccf7ed834801d8e9d2cb5fd3c9b9b8eaa0b29dca36
|