Skip to main content

ytpaw

ytpaw is a small Python library for YouTube search and public metadata collection. It intentionally does not download media, implement SABR or signature deciphering, or merge audio and video streams.

Shared model field names follow NAMING_STANDARD.md, while YouTube-specific extensions retain their provider-specific meaning.

All Innertube, HTML, and OAuth requests use curl_cffi with browser-compatible TLS handling. Proxy, timeout, retry, OAuth, and PO-token options remain available through YouTubeClient.

Installation

pip install ytpaw

For development and tests:

pip install -e ".[test]"
python -m pytest

The default suite is network-free. Run the real-YouTube integration suite explicitly when network access and rate-limit budget are available:

$env:YTPAW_RUN_INTEGRATION = "1"
python -m pytest tests/integration -m integration -s

For the documentation site:

uv sync --extra docs
uv run sphinx-build -b html docs docs/_build/html

The Russian README is available in README.ru.md.

Quick Start

from ytpaw import YouTubeClient

client = YouTubeClient(min_interval=1.0, retries=3)
video = client.video_stats("https://www.youtube.com/watch?v=dQw4w9WgXcQ")

print(video.title, video.view_count, video.like_count, video.comment_count)
print(client.channel_stats("UC_x5XG1OV2P6uZZ5xm2JYQ"))

for result in client.search("python http client"):
    print(result.result_type, result.id, result.title)

API

  • YouTubeClient.video_stats(url) returns VideoStats for a YouTube video.
  • YouTubeClient.channel_stats(profile_id_or_url) returns ChannelStats.
  • YouTubeClient.channel_videos(profile_id_or_url, limit) yields available video statistics from newest to oldest and follows continuation pages.
  • YouTubeClient.related_videos(url, depth=0) traverses side-panel recommendations breadth-first and yields RelatedVideo objects.
  • YouTubeClient.search(query, filters=None) returns video, channel, and playlist SearchResult objects.
  • is_video_url(value), is_channel_url(value), and youtube_url_type(value) classify ambiguous input safely before selecting a client method.
  • extract_video_stats() and extract_channel_stats() parse saved responses without making network requests.

channel_videos() accepts channel IDs, @handles, URLs with or without a scheme, /channel/ID, /@handle, /c/name, /user/name, and /videos suffixes. related_videos(depth=0) returns direct recommendations only; the input video itself is never yielded.

Every model keeps the original response in raw. The field is hidden from repr() because responses can be large and may contain service metadata.

Network Context

The client supports proxy, timeout, retries, and min_interval for corporate or rate-limited environments. visitor_data, oauth_token, and optional PO-token integration are supported where YouTube requires a specific request context. These options do not bypass CAPTCHA, authentication, authorization, access controls, or YouTube policies.

client = YouTubeClient(
    proxy="http://127.0.0.1:8080",
    timeout=20,
    retries=4,
    min_interval=0.5,
    visitor_data="VISITOR_DATA",
    oauth_token="OAUTH_ACCESS_TOKEN",
    language="en",
    region="US",
)

The default locale is en-US so numeric labels are stable for parsing. Set language and region when needed; localized units such as тыс., Mio., million, and mil are supported.

OAuth

client = YouTubeClient(use_oauth=True, allow_oauth_cache=True)

The first run starts Google's Device Flow and displays a verification URL and one-time code. Tokens are refreshed automatically and stored in ~/.cache/ytpaw/tokens.json by default. Do not publish or commit this file. Set allow_oauth_cache=False to disable persistence, or pass oauth_verifier for a GUI or custom CLI.

PO Tokens

from ytpaw import YouTubeClient, generate_po_token

po_token = generate_po_token("dQw4w9WgXcQ")
client = YouTubeClient(
    visitor_data="VISITOR_DATA_FROM_THE_SAME_CONTEXT",
    po_token=po_token,
)

Install the optional generator dependencies with pytubefix and nodejs-wheel-binaries, or pass a po_token_verifier returning (visitor_data, po_token). Tokens are never fabricated. Missing BotGuard assets or Node.js results in RequestError.

Windows Encoding

Use UTF-8 output when running the smoke script on Windows:

python -X utf8 .\da.py

Limitations and Safety

YouTube changes internal response schemas and applies rate limits. Public statistics may be incomplete for private, removed, age-restricted, or blocked content. Live requests are not deterministic.

Do not log or commit access tokens, refresh tokens, bearer headers, visitor data, PO tokens, or OAuth cache files. Use proxies only when you are authorized to do so. The project is MIT licensed.

Metadata

Release files for ytpaw 0.1.0

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

Source distribution (sdist)

Source distribution for ytpaw 0.1.0
File Size Uploaded
ytpaw-0.1.0.tar.gz 35.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ytpaw 0.1.0
File Interpreter ABI Platform
ytpaw-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 64.0 kB

Release files / ytpaw-0.1.0.tar.gz

Download URL ytpaw-0.1.0.tar.gz
Size 35.3 kB
Tags Source
SHA-256 checksum
How to use checksums
bdda22519a84882a3e2ccb594118f5e88b93cac037c13ec7dde2ba4d318eefe6
BLAKE2b-256 checksum
How to use checksums
6775977dede99d55a5b5d021ac791ab1257f79e0a2b45ba4007a2f337817c18b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ytpaw-0.1.0-py3-none-any.whl

Download URL ytpaw-0.1.0-py3-none-any.whl
Size 28.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
403c32062d2fc661b30a7b047b3fb7b5252dff9865690a3bf58cf26cf960fd0b
BLAKE2b-256 checksum
How to use checksums
f869afb919b3dcad4cc0c158815e5faac1b71cab4ab3f6521ec447b079b2db78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release 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