Simple YouTube API
An unofficial lightweight Python wrapper for extracting video metadata and transcripts from YouTube videos.
Features
- 🎥 Extract video metadata (title, thumbnail, description)
- 📝 Get video transcripts in various languages
- ⚡ Simple and easy to use interface
- 🔒 No API key required
Installation
uv (a Python package and project manager) 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
yt = YouTubeAPI()
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
metadata, transcript = yt.fetch_all(url_or_id=url)
print(f"Metadata: {metadata.to_dict()}")
print(f"Transcript: {transcript}")
Example Output:
Metadata: {
'video_id': 'dQw4w9WgXcQ',
'title': 'Rick Astley - Never Gonna Give You Up (Official Video) (4K Remaster)',
'img_url': 'https://i.ytimg.com/vi/dQw4w9WgXcQ/maxresdefault.jpg',
'description': 'The official video for “Never Gonna Give You Up” by Rick Astley. Never: The Autobiography 📚 OUT NOW! Follow this link to get your copy and listen to Rick’s ...'
}
Transcript: [
{'text': '[♪♪♪]', 'start': 1.36, 'duration': 1.68},
{'text': "♪ We're no strangers to love ♪", 'start': 18.64, 'duration': 3.24},
...
]
More examples can be found in the examples directory.
API Reference
YouTubeAPI Class
YouTubeAPI()
Initializes the API client.
fetch_metadata(url_or_id: str) -> VideoMetadata
Retrieves metadata for a specific video.
| Parameter | Type | Description |
|---|---|---|
url_or_id |
str |
The URL or ID of the YouTube video. |
Returns: VideoMetadata object containing video_id, title, img_url, and description. Use .to_dict() to convert to a dictionary.
Note: description is not consistent about fully including the video description. It may be truncated in some cases.
fetch_transcript(url_or_id: str, language_code: str = "en", output_format: str = "json") -> list[dict] | str
Retrieves the transcript for a specific video.
| Parameter | Type | Default | Description |
|---|---|---|---|
url_or_id |
str |
- | The URL or ID of the YouTube video. |
language_code |
str |
"en" |
The language code for the desired transcript. |
output_format |
str |
"json" |
Output format: "json" (list of dicts) or "text" (string). |
Returns: A list of dictionaries (JSON) or a plain string containing the transcript.
fetch_all(url_or_id: str, language_code: str = "en", output_format: str = "json") -> tuple
Convenience method to retrieve both metadata and transcript simultaneously.
| Parameter | Type | Default | Description |
|---|---|---|---|
url_or_id |
str |
- | The URL or ID of the YouTube video. |
language_code |
str |
"en" |
The language code for the desired transcript. |
output_format |
str |
"json" |
Output format: "json" (list of dicts) or "text" (string). |
Returns: A tuple (metadata, transcript). If an error occurs for either part, that element will be None.
Error Handling
The library includes custom exceptions:
YouTubeAPIError: For YouTube API related errors.IpBlocked: When IP is blocked by YouTube.RequestBlocked: When request is blocked by YouTube.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.
Limitations & gotchas
- Not all videos have transcripts available.
- Transcripts may not be available in all languages.
- Some videos only have auto-generated transcripts which may not be accurate.
- The library relies on web scraping techniques, which may break if YouTube changes its page structure.
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
Metadata
Release files for simple-yt-api 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| simple_yt_api-4.1.0.tar.gz | 6.3 kB | Without provenance | Details for simple_yt_api-4.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| simple_yt_api-4.1.0-py3-none-any.whl | Python 3 | none | any | Details for simple_yt_api-4.1.0-py3-none-any.whl |
Total release size: 14.7 kB
Release files / simple_yt_api-4.1.0.tar.gz
| Download URL | simple_yt_api-4.1.0.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f8d3f9252fae4af834695e11d5c4b24f2d4fe0c39f9cde94aba25d9d7ee941cb
|
|
BLAKE2b-256 checksum How to use checksums |
12933e7506cc8e1c7fb33ccfed513ea316228894f445374450d7254133a67ca1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / simple_yt_api-4.1.0-py3-none-any.whl
| Download URL | simple_yt_api-4.1.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ddbc9c9610c46675c1384da97fa915d730c5fc4defdae5169a517874394d412d
|
|
BLAKE2b-256 checksum How to use checksums |
22160ddc72c2d2b71b26aae70a7fb50f9600601ab2f2c3b79b3c9f4718259b19
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.8 {"installer":{"name":"uv","version":"0.11.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for simple-yt-api 4.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.