Skip to main content

A lightweight, regex-based YouTube search library without API keys.

Project description

py-youtube-search

A lightweight, asynchronous Python library to search YouTube videos programmatically without an API key. It scrapes search results using aiohttp and re, making it fast, robust, and perfect for high-performance applications.

Features

  • Async Support: Fully asynchronous using aiohttp for non-blocking execution.
  • No API Key Required: Search YouTube directly without setting up Google Cloud projects.
  • Advanced Filtering: Built-in support for duration (Medium 3-20m, Long >20m) and upload date filters.
  • Rich Data Extraction: Extracts Video ID, Title, Duration, and View Count using optimized regex.

Installation

pip install py-youtube-search

Quick Start

1. Basic Async Search

Fetch the top results for any keyword asynchronously.

import asyncio
from py_youtube_search import YouTubeSearch

async def main():
    # 1. Initialize the search (no network call yet)
    yt = YouTubeSearch("Python async tutorials", limit=5)
    
    # 2. Await the search results
    videos = await yt.search()

    for v in videos:
        print(f"Title: {v['title']}")
        print(f"Duration: {v['duration']}")
        print(f"Views: {v['views']}")
        print(f"Link: https://www.youtube.com/watch?v={v['id']}\n")

if __name__ == "__main__":
    asyncio.run(main())

2. Advanced Search with Filters

Search for specific content, like long-form videos (>20m) uploaded this week.

import asyncio
from py_youtube_search import YouTubeSearch, Filters

async def main():
    # Use the Filters class for readable constants
    yt = YouTubeSearch("LangGraph", sp=Filters.long_this_week, limit=3)
    
    videos = await yt.search()

    for v in videos:
        print(f"🎥 {v['title']} | ⏱ {v['duration']} | 👁 {v['views']}")

if __name__ == "__main__":
    asyncio.run(main())

Available Filters

Pass these constants into the sp parameter of YouTubeSearch.

Duration: Medium (3 - 20 Minutes)

Filter Attribute Description
Filters.medium_today Uploaded Today
Filters.medium_this_week Uploaded This Week
Filters.medium_this_month Uploaded This Month
Filters.medium_this_year Uploaded This Year

Duration: Long (Over 20 Minutes)

Filter Attribute Description
Filters.long_today Uploaded Today
Filters.long_this_week Uploaded This Week
Filters.long_this_month Uploaded This Month
Filters.long_this_year Uploaded This Year

Data Structure

The .search() method returns a list of dictionaries:

[
  {
    "id": "lDoYisPfcck",
    "title": "Hack the planet! LangGraph AI HackBot Dev & Q/A",
    "duration": "1:05:23",
    "views": "1.2K views",
    "url_suffix": "/watch?v=lDoYisPfcck"
  }
]

Dependencies

  • aiohttp (for async requests)

License

MIT License. See LICENSE file for details.

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

py_youtube_search-0.2.1.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

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

py_youtube_search-0.2.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file py_youtube_search-0.2.1.tar.gz.

File metadata

  • Download URL: py_youtube_search-0.2.1.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for py_youtube_search-0.2.1.tar.gz
Algorithm Hash digest
SHA256 33ecf57781b361c556fd3629a9c18bbfab9dcdae05cd58df80ca175aa27dcb68
MD5 8f590208676ca8987eea43bdc1ad00f1
BLAKE2b-256 b5d7bc1d7951e088a88542ad13c0669ca8ff3383e8ec848135c61c77aaf8058e

See more details on using hashes here.

File details

Details for the file py_youtube_search-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_youtube_search-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17a8fe3579ba9e71062d0346924a2e2ca78873df216a769338cd3b5207a6a6a1
MD5 61355e3ad8ceaa54c5cf771085447993
BLAKE2b-256 e507067d219946d6b037ea7ad0449a73f315d29ac71025998ae29fbc0942435f

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