A simple and easy-to-use unofficial YouTube API Wrapper.
Project description
Simple YouTube API
An unofficial lightweight Python wrapper for extracting video metadata and transcripts from YouTube videos.
Features
- 🎥 Extract video metadata (title, thumbnail, short description)
- 📝 Get video transcripts in various languages
- ⚡ Simple and easy to use interface
- 🔒 No API key required
Installation
uv is recommended for managing and installing packages in isolated environments.
uv add simple-yt-api
You can also install it using pip:
pip install simple-yt-api
Quick Start
from simple_yt_api import YouTubeAPI
# Initialize
yt = YouTubeAPI()
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
# Get video metadata
metadata = yt.data(url=url)
print(metadata["title"])
# Get video transcript
transcript = yt.get_transcript(
url=url,
language_code="tr",
as_dict=True
) # Get Turkish transcript. Defaults to "en".
print(transcript)
# Or get both metadata and transcript at once
data, transcript = yt.get_video_data_and_transcript(
url=url,
language_code="es",
as_dict=False # Return transcript as plain text
)
API Reference
YouTubeAPI Class
YouTubeAPI()
Initializes the API client.
data(url: str) -> dict
Returns video metadata dictionary containing:
video_id: YouTube video IDtitle: Video titleimg_url: Thumbnail URLshort_description: Video description
get_transcript(url: str, language_code: str = "en", as_dict: bool = True) -> list[dict] | str
Get video transcript in the specified languages.
url (str): The URL of the YouTube video.language_code (str, optional): The language code for the desired transcript. Defaults to "en".as_dict (bool, optional): IfTrue, returns the transcript as a list of dictionaries; otherwise, returns the transcript as a string. Defaults toTrue.
get_video_data_and_transcript(url: str, language_code: str = "en", as_dict: bool = True) -> tuple
Returns both video metadata and transcript. If there is an error, that spot in the tuple will have None instead of a value.
url (str): The URL of the YouTube video.language_code (str, optional): The language code for the desired transcript. Defaults to "en".as_dict (bool, optional): IfTrue, returns the transcript as a list of dictionaries; otherwise, returns the transcript as a string. Defaults toTrue.
Error Handling
The library includes custom exceptions:
NoVideoFound: When a video is not accessible or doesn't exist.NoMetadataFound: When no metadata is found for the video.TranscriptsDisabled: When transcripts are not available for the video.NoTranscriptFound: When no transcript is available for the video.
Warning
Sending too many requests in a short period might lead to your IP address being temporarily blocked by YouTube. Use responsibly.
License
This project is licensed under the MIT License.
Links
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 simple_yt_api-3.0.1.tar.gz.
File metadata
- Download URL: simple_yt_api-3.0.1.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa38bed836262704f98dbf99e12cc7561e23be1c4c348ad79ace49f37f1fd0dc
|
|
| MD5 |
d7f5db932bf7de853009eced0862ef40
|
|
| BLAKE2b-256 |
f3080afdad058cf3e022cd55c5ae5c28868e65ea291fad13817ba2a9e181fa9f
|
File details
Details for the file simple_yt_api-3.0.1-py3-none-any.whl.
File metadata
- Download URL: simple_yt_api-3.0.1-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb93b4fad156ec1aafee7d2160e5f13eb13a3ab7baf3dc0a4e10be83515f9bf0
|
|
| MD5 |
74cad83ae7272176d3b545d856d04acd
|
|
| BLAKE2b-256 |
58a2167b7b4406127539ef6239ae62e3ff7040f08f1984faf09d3b6bfd3673f2
|