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 with a YouTube URL
url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
yt = YouTubeAPI(url)

# Get video metadata
metadata = yt.data()
print(metadata["title"])

# Get video transcript
transcript = yt.get_transcript(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(
    language_code="es",
    as_dict=False  # Return transcript as plain text
)

API Reference

YouTubeAPI Class

YouTubeAPI(url: str)

Initialize the API with a YouTube video URL.

data() -> dict

Returns video metadata dictionary containing:

  • video_id: YouTube video ID
  • title: Video title
  • img_url: Thumbnail URL
  • short_description: Video description

get_transcript(language_code: str = "en", as_dict: bool = True) -> list[dict] | str

Get video transcript in specified languages.

  • 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(language_code: str = "en", as_dict: bool = True) -> tuple

Returns both video metadata and transcript for a YouTube video in one call without worrying about errors.

Error Handling

The library includes custom exceptions:

  • InvalidURL: For invalid YouTube URL format.
  • 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

  • requests==2.32.3
  • beautifulsoup4==4.13.4
  • youtube-transcript-api==1.0.3

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-2.0.1.tar.gz (5.5 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-2.0.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simple_yt_api-2.0.1.tar.gz
  • Upload date:
  • Size: 5.5 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-2.0.1.tar.gz
Algorithm Hash digest
SHA256 bd2d6444c9555782aee1268d5036c89ba5781312c10433b419e078808c8fd07c
MD5 0465ae738879cc0130e42f1a46c5f19b
BLAKE2b-256 2ece9c5126294f156c2c1daee8dc405899ea8d39635551b122809119b59cc07b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simple_yt_api-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 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-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c80f99da24289dfd4590d3472f71d6c5e12eecbb328d9dbed5f1de7332ce64df
MD5 e3103cdfa62eabf208869d80f8e73325
BLAKE2b-256 6cf2427702cf5f706c4b5d89dc3a0273b1eab50b3fabaf4ac668829cccac429e

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