Skip to main content

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

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)

# 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 ID
  • title: Video title
  • img_url: Thumbnail URL
  • short_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): If True, returns the transcript as a list of dictionaries; otherwise, returns the transcript as a string. Defaults to True.

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): If True, returns the transcript as a list of dictionaries; otherwise, returns the transcript as a string. Defaults to True.

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.

Requirements

  • Python >= 3.10
  • requests==2.32.4
  • beautifulsoup4==4.13.4
  • youtube-transcript-api==1.1.0

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-3.0.0.tar.gz (5.4 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-3.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_yt_api-3.0.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for simple_yt_api-3.0.0.tar.gz
Algorithm Hash digest
SHA256 8ddb2dcf164e7dbaf38b65d9079f3b88fd16c11c94294ec7e2cdc1163a682dd7
MD5 b6795fb9441a637c3545440ac4810a5b
BLAKE2b-256 77afedc5ea2ab587648915e919eb6b9c952a30edf0b979f25a1aba439bf0fa09

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_yt_api-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for simple_yt_api-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10a5a72b194a4cba569561283524fc16b70ac5392e34941a7df4e925c7195276
MD5 58ddf038dc49fed9dc9a1a18bad83c71
BLAKE2b-256 c3261073b8c39088da97337a795b670cbfe448278994071c58072468f82bb8f0

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