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())
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.

Metadata

Release files for py-yt-search 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-yt-search 0.8.2
File Size Uploaded Provenance Actions
py_yt_search-0.8.2.tar.gz 741.2 kB With provenance Details for py_yt_search-0.8.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for py-yt-search 0.8.2
File Interpreter ABI Platform Actions
py_yt_search-0.8.2-py3-none-any.whl Python 3 none any Details for py_yt_search-0.8.2-py3-none-any.whl

Total release size: 1.5 MB

Release files / py_yt_search-0.8.2.tar.gz

Download URL py_yt_search-0.8.2.tar.gz
Size 741.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1a460ba4ffd3e466ab110a84d02120cf957a1c054cfa255e0760103b51026b0e
BLAKE2b-256 checksum
How to use checksums
b24b9d0c2ee742b4a5e474a62258ef61e300562cee5e5ffb6bd24d25b907aeb4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Release files / py_yt_search-0.8.2-py3-none-any.whl

Download URL py_yt_search-0.8.2-py3-none-any.whl
Size 755.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4770774ac1794b8532f07a95042608c2a531a9fbacf693f8d79408b0c07a607d
BLAKE2b-256 checksum
How to use checksums
61a64fb274c5c118a4ee7fe6842b90b930b9d30b58474c9be22cc30e520c8e57
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

Security for py-yt-search 0.8.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for py_yt_search-0.8.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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