Skip to main content

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

Project description

py-youtube-search

A lightweight, zero-dependency Python library to search YouTube videos programmatically without an API key. This library uses standard Python libraries (urllib and re) to scrape search results, making it fast, robust, and easy to integrate into any project.

Features

  • No API Key Required: Search YouTube directly without setting up Google Cloud projects or billing.
  • Zero External Dependencies: Built entirely using Python's standard library (urllib, re). No requests, selenium, or beautifulsoup needed.
  • Advanced Filtering: Built-in support for duration (Medium 3-20m, Long >20m) and upload date filters (Today, Week, Month, Year).
  • Rich Data Extraction: Robustly extracts Video ID, Title, Duration, and View Count.

Installation

You can install the package via pip:

pip install py-youtube-search

Quick Start

1. Basic Search

Fetch the top results for any keyword.

from py_youtube_search import YouTubeSearch

# Search for the top 5 results for "Python tutorials"
search = YouTubeSearch("Python tutorials", limit=5)
videos = search.videos()

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")

2. Advanced Search with Filters

Search for specific types of content, such as long-form tutorials uploaded this week.

from py_youtube_search import YouTubeSearch, Filters

# Search for "LangGraph" videos over 20 minutes long, uploaded this week
# Use the Filters class to access constants
search = YouTubeSearch("LangGraph", sp=Filters.long_this_week, limit=3)
videos = search.videos()

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

Available Filters

You can access these filters using the Filters class (e.g., Filters.long_today).

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 videos() method returns a list of dictionaries with the following structure:

[
  {
    "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"
  },
  {
    "id": "5LXLmUsEM20",
    "title": "LangGraph Workflow Patterns - Part 1/10",
    "duration": "42 seconds",
    "views": "500 views",
    "url_suffix": "/watch?v=5LXLmUsEM20"
  }
]

License

This project is licensed under the MIT License - see below for details.

MIT License

Copyright (c) 2026

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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.0.tar.gz (4.3 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.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py_youtube_search-0.2.0.tar.gz
  • Upload date:
  • Size: 4.3 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.0.tar.gz
Algorithm Hash digest
SHA256 884f7be3f244d4267de035fe1a7fe139d92aa2724277c88220517ef5c162cd47
MD5 5d01faaf752c274ff33dbe5c183c993b
BLAKE2b-256 f0e1621572f88073f36b6d2a502006e3792018789e682ad0bdb79f2836c41451

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for py_youtube_search-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 941ac8bf0414f49d2c41700020176e66e526689abdcc84b3ba2d762e822197a0
MD5 d2aa020889d7824f2411e1cafa7c8478
BLAKE2b-256 213b87f069055e1d1414c47251485005059d8886a2a08f55d3e899e6823f006e

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