Documentation Index
Fetch the complete documentation index at: https://mintlify.com/vsmutok/ytscrape/llms.txt
Use this file to discover all available pages before exploring further.
InnerTubeClient is the low-level HTTP layer that underpins every network call in ytscrape. It owns the requests.Session, lazily bootstraps the InnerTube context (API key, visitor data, client version) from the YouTube home page, and exposes thin wrappers around the search, player, browse, and next InnerTube endpoints. It knows nothing about pagination, data models, or response parsing — that logic lives in the higher-level YouTube facade.
Most users should work exclusively through YouTube and never touch InnerTubeClient directly. The main reason to instantiate it yourself is to inject a custom requests.Session — for example to add proxy routing, retry logic, or a custom User-Agent — and then pass it into YouTube via the client argument.
Unless you have a specific reason to work at the HTTP level, use the
YouTube facade instead. It handles pagination, model
parsing, and resource management for you.Custom session injection example
The example below wires up anHTTPAdapter with automatic retries and an HTTPS proxy, then hands the session to YouTube so all scraping goes through it.
Constructor
A pre-configured
requests.Session
to use for all HTTP calls. When omitted a new default session is created. Injecting a custom
session is the primary reason to instantiate InnerTubeClient directly — it lets you add retry
adapters, proxy configuration, cookie jars, or certificate settings without modifying ytscrape
internals.The
User-Agent header sent with every request. The default mimics a recent Chrome browser on
Windows, which is what YouTube expects. Override it only when you have a specific need, such as
testing or compliance requirements.Per-request timeout in seconds. Applied to every
GET and POST call made by this client.A
Locale object that bundles language and country together. When provided, the
language and region arguments are ignored. Omit it to let the client build a Locale from
the individual language and region values.The
hl (host language) value embedded in every InnerTube request context. Accepts a
Language enum member or a raw ISO 639-1 code such as "fr" or "ja". Ignored
when locale is provided.The
gl (geolocation) value embedded in every InnerTube request context. Accepts a
Country enum member or a raw ISO 3166-1 alpha-2 code such as "GB" or "JP".
Ignored when locale is provided.A
ContextExtractor strategy object used to parse the InnerTube context (API
key, visitor data, client version) out of the YouTube home page HTML. When omitted the default
ContextExtractor is used. Override for testing or when YouTube changes its initialization
script format.Properties
locale
Locale (language + country pair) used for all requests. Set at construction
time from either the locale argument or the language / region pair.
context
InnerTubeContext holding the API key, visitor data token, and client version
string required for authenticated InnerTube calls. The context is fetched lazily on first
access — the client makes a GET request to the YouTube home page and parses the initialization
script. Subsequent accesses return the cached value.
The first call to any endpoint method (or to
context directly) will trigger an HTTP request to
https://www.youtube.com to bootstrap the context. This is normal behaviour.Methods
search
Call the raw InnerTube search endpoint.
The search query string. Used for the first page of results. Either
query or continuation
must be provided.Base64-encoded filter parameters. Constructed by
SearchFilter and passed
through as-is to the InnerTube payload. Omit for unfiltered results.Opaque continuation token for fetching subsequent pages. When provided,
query and params are
ignored.dict[str, Any] — raw InnerTube JSON response. Pass to SearchResults or parse
manually.
player
Call the raw InnerTube player endpoint for a single video.
The 11-character YouTube video id.
The InnerTube client identity to send.
"WEB" is used for standard metadata. "ANDROID" is
preferred for caption track lists, as it exposes them more reliably (the same approach used by
youtube-transcript-api).dict[str, Any] — raw InnerTube player response containing video metadata, streaming
URLs, and caption track manifests.
browse
Call the raw InnerTube browse endpoint, used for channels, tabs, and shelves.
The channel or tab id to browse (typically a
UC… channel id). Either browse_id or
continuation must drive the call — when continuation is provided, browse_id and params
are ignored.Base64-encoded parameters for selecting a specific tab or continuation within a channel page.
Opaque continuation token for fetching subsequent pages of a browse result.
dict[str, Any] — raw InnerTube browse response.
next
Call the raw InnerTube next endpoint, used for the watch page and comment threads.
The 11-character video id. Used to load the watch-page data, which contains the initial
continuation token that opens the comments section. Either
video_id or continuation must be
provided.Opaque continuation token for fetching comment threads, individual reply threads, or additional
pages of comments. When provided,
video_id is ignored.dict[str, Any] — raw InnerTube next response.
get_html
Fetch an arbitrary YouTube page and return its full HTML body.
The full URL of a YouTube page (e.g. a channel or user page) to fetch.
str — the raw HTML response body. Raises RequestError on any HTTP or network
error.
get_text
Fetch an arbitrary URL and return the response body as plain text.
The full URL to fetch. Primarily used internally to download timedtext XML caption files, but
available for any text resource.
str — the response body decoded as text. Raises RequestError on any HTTP or
network error.
close
Close the underlying requests.Session and release all associated resources.
None