YouTube serves localised content based on two parameters: the interface language (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.
hl) and the content region (gl). Setting them tells YouTube which language to use for UI text and which country’s content catalogue to surface. ytscrape lets you control both when creating a YouTube instance.
Passing raw ISO codes
The simplest way is to pass plain ISO codes directly toYouTube(). They are validated and normalised for you:
language accepts an ISO 639-1 two-letter code (e.g. "en", "uk", "de").region accepts an ISO 3166-1 alpha-2 two-letter code (e.g. "US", "UA", "DE").
The Language and Country value objects
Language and Country are thin, self-validating value objects. They wrap the raw ISO code and normalise its casing on construction — lower-case for language, upper-case for country. You can use them interchangeably with plain strings anywhere ytscrape accepts a language or region:
The Locale object
A Locale bundles a Language and a Country together. Build one when you want to construct the locale separately and reuse it across multiple YouTube instances:
Locale also accepts raw strings for both fields — it coerces them to Language and Country automatically:
Locale.of() classmethod is a convenience alternative that accepts None for either argument and falls back to the defaults ("en" / "US"):
Validation
Invalid codes are rejected early with a clear error message rather than silently producing a broken request:How locale is sent
The chosen locale affects every request in two ways:- InnerTube context —
hl(language code) andgl(country code) are embedded in the JSON payload of every API call. Accept-Languageheader — set to a value likeuk-UA,uk;q=0.9, which also influences the HTML YouTube returns for context extraction.
Full example
Supported code formats
| Parameter | Format | Example |
|---|---|---|
language | ISO 639-1 (two-letter, lower-cased) | "en", "uk", "de", "fr" |
region | ISO 3166-1 alpha-2 (two-letter, upper-cased) | "US", "UA", "DE", "FR" |
ytscrape validates codes against the official ISO lists using the
pycountry library — there is no hard-coded whitelist. Any code that pycountry recognises will work, so newly added or uncommon codes are supported automatically.