Skip to main content

A simple and easy-to-use unofficial YouTube API Wrapper.

Project description

Simple YouTube API

PyPI version Downloads License: MIT

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simple_yt_api-4.1.0.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_yt_api-4.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file simple_yt_api-4.1.0.tar.gz.

File metadata

  • Download URL: simple_yt_api-4.1.0.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for simple_yt_api-4.1.0.tar.gz
Algorithm Hash digest
SHA256 f8d3f9252fae4af834695e11d5c4b24f2d4fe0c39f9cde94aba25d9d7ee941cb
MD5 9952f0ba51bbd2b39ec46eb10978b3c3
BLAKE2b-256 12933e7506cc8e1c7fb33ccfed513ea316228894f445374450d7254133a67ca1

See more details on using hashes here.

File details

Details for the file simple_yt_api-4.1.0-py3-none-any.whl.

File metadata

  • Download URL: simple_yt_api-4.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for simple_yt_api-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ddbc9c9610c46675c1384da97fa915d730c5fc4defdae5169a517874394d412d
MD5 4de0f20b5023318f46be587f6c1867d1
BLAKE2b-256 22160ddc72c2d2b71b26aae70a7fb50f9600601ab2f2c3b79b3c9f4718259b19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page