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, short 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',
    'short_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 short_description. Use .to_dict() to convert to a dictionary.

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.0.0.tar.gz (5.6 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.0.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_yt_api-4.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.0.0.tar.gz
Algorithm Hash digest
SHA256 8f2a069db13d039055f18a5cb582eecf05a5351d78ebc08e4dbce0a4aff2d3cc
MD5 0bd42d98972186b1db159817bbcfd9ab
BLAKE2b-256 ee2416c45ee92bae97ceee9ad58bc8b80e3974ba2b24f35639d64632dffe82fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_yt_api-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d7d3737af00fccb681890aa901fca651215a96de9ed9c693f65f268ba978214d
MD5 0f206ce957266c59a3dc9d84e611c3e8
BLAKE2b-256 c1a000652ae865f8774e76ab5d3afda5851f7f3a4e454c4987e607fc56872ac8

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