Skip to main content

YouTube Data Extraction with py-yt-search

py-yt-search is an async-first Python library for searching and retrieving YouTube data, including videos, channels, playlists, transcripts, search suggestions, recommendations, and HYPE HINT momentum analytics.

Features

  • Async-first architecture: built for high-performance asyncio applications.
  • YouTube Search: search for videos, channels, playlists, or perform filtered search.
  • Channel Search: search for videos within a specific YouTube channel.
  • HYPE HINT: calculate momentum, view velocity, recency boost, and rank videos by hype scores.
  • Video & Format Details: retrieve detailed video metadata, formats, and streaming data.
  • Playlist Details: fetch full playlist info and paginate through playlist videos (supports standard & YouTube Mix playlists).
  • Video Transcripts: extract video subtitles/transcripts across supported languages.
  • Suggestions & Recommendations: fetch live search suggestions and homepage/related video recommendations.
  • Resilient Network Layer: automatic client profile rotation, visitor token persistence, and retry backoff.

Installation

pip install py-yt-search

Or install directly from GitHub:

pip install git+https://github.com/AshokShau/py-yt-search.git

Usage

All API calls in py-yt-search are asynchronous and should be executed within an asyncio event loop.

1. Search YouTube

import asyncio
from py_yt import Search, VideosSearch, ChannelsSearch, PlaylistsSearch

async def main():
    # General Search (videos, channels, playlists)
    search = Search('Python programming', limit=5)
    result = await search.next()
    print("Search results count:", len(result['result']))

    # Video Search Only
    videos_search = VideosSearch('Python tutorial', limit=5)
    videos_result = await videos_search.next()
    print("First video title:", videos_result['result'][0]['title'])

    # Channels Search
    channels_search = ChannelsSearch('Python Software Foundation', limit=1)
    channels_result = await channels_search.next()
    print("Channel ID:", channels_result['result'][0]['id'])

    # Playlists Search
    playlists_search = PlaylistsSearch('Python Data Science', limit=2)
    playlists_result = await playlists_search.next()
    print("Playlist ID:", playlists_result['result'][0]['id'])

asyncio.run(main())

2. HYPE HINT Momentum Analytics

Calculate video hype scores (0.0 - 100.0) based on view velocity, publication age, log view scaling, and recency boost.

import asyncio
from py_yt import VideosSearch, HypeHint

async def main():
    search = VideosSearch('artificial intelligence', limit=10)
    res = await search.next()
    videos = res.get('result', [])

    # Calculate hype score for a single video
    for video in videos:
        analysis = HypeHint.analyze_video(video)
        print(f"Title: {video['title']}")
        print(f"Hype Score: {analysis['score']}/100 ({analysis['level']})")
        print(f"View Velocity: {analysis['velocity_views_per_hour']} views/hr\n")

    # Rank a list of videos by hype score descending
    ranked_videos = HypeHint.rank(videos)
    print("Top Hyped Video:", ranked_videos[0]['title'])

asyncio.run(main())

3. Get Video Details

import asyncio
from py_yt import Video

async def main():
    # Get video info
    video_data = await Video.get('z0GKGpObgPY')
    print(video_data)

    # Get streaming formats
    formats = await Video.getFormats('z0GKGpObgPY')
    print(formats)

asyncio.run(main())

4. Get Playlist Details

import asyncio
from py_yt import Playlist

async def main():
    playlist_url = 'https://www.youtube.com/playlist?list=PLRBp0Fe2GpgmsW46rJyudVFlY6IYjFBIK'
    playlist = Playlist(playlist_url)
    
    # Paginate through playlist videos
    await playlist.getNextVideos()
    print(f"Fetched {len(playlist.videos)} videos.")
    print("Has more videos:", playlist.hasMoreVideos)

asyncio.run(main())

5. Fetch Search Suggestions

import asyncio
from py_yt import Suggestions

async def main():
    suggestions = await Suggestions.get('python', language='en', region='US')
    print(suggestions['result'])

asyncio.run(main())

6. Retrieve Video Transcripts

import asyncio
from py_yt import Transcript

async def main():
    transcript = await Transcript.get('https://www.youtube.com/watch?v=L7kF4MXXCoA')
    print(transcript)

asyncio.run(main())

7. Recommendations & Related Videos

import asyncio
from py_yt import Recommendations

async def main():
    # Get homepage recommendations
    home = await Recommendations.getHome(limit=5)
    print("Home videos:", len(home['result']))

    # Get related / suggested videos for a watch URL
    related = await Recommendations.getRelated('https://www.youtube.com/watch?v=z0GKGpObgPY', limit=5)
    print("Related videos:", len(related['result']))

asyncio.run(main())

Error Handling

py-yt-search defines custom exception types under py_yt.exceptions:

  • PyYTSearchError: base exception class.
  • ParsingError: raised when parsing YouTube API or HTML structure fails.
  • RequestError: raised when HTTP network requests fail.
  • VideoNotFoundError: raised when video details are missing or inaccessible.
from py_yt import VideosSearch
from py_yt.exceptions import PyYTSearchError

async def safe_search():
    try:
        search = VideosSearch('python', limit=5)
        res = await search.next()
        print(res)
    except PyYTSearchError as e:
        print(f"py-yt-search error occurred: {e}")

License

This project is licensed under the MIT License. See the LICENSE file for details.

Credits

This project is based on youtube-search-python by Alex Mercer.

Download files

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

Source Distribution

py_yt_search-0.8.0.tar.gz (671.0 kB view details)

Uploaded Source

Built Distribution

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

py_yt_search-0.8.0-py3-none-any.whl (684.9 kB view details)

Uploaded Python 3

File details

Details for the file py_yt_search-0.8.0.tar.gz.

File metadata

  • Download URL: py_yt_search-0.8.0.tar.gz
  • Upload date:
  • Size: 671.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for py_yt_search-0.8.0.tar.gz
Algorithm Hash digest
SHA256 4fe95b366c5b800a4b85385b457b136cdf51ec6f6bc871fddf1fea74e4635b2a
MD5 36a31a0c6ef03aa556de1bbd8f2e0997
BLAKE2b-256 39296c4270fc835f1aefd8428ba148b61f555d461a519a5901b9966ea9773b3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_yt_search-0.8.0.tar.gz:

Publisher: publish.yml on AshokShau/py-yt-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_yt_search-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: py_yt_search-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 684.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for py_yt_search-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8f1ef45f5637b952e018438df183e77919a43125b13b648bf506668a2e35a9f
MD5 870e4a8aac84577d182b85f0c185f4c3
BLAKE2b-256 36c9a36dae5d0ecb2763752a39cb53cb4e3e0a074e2b66ddbfad0bf666274817

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_yt_search-0.8.0-py3-none-any.whl:

Publisher: publish.yml on AshokShau/py-yt-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.9

2 files

0.5.8

2 files

0.5.7

2 files

0.5.6

1 file

0.5.5

1 file

0.5.4

1 file

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5

1 file

0.4

1 file

0.3

1 file

0.2

2 files

0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page