TheDocumentation 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.
locale module provides three immutable value objects — Language, Country, and Locale — that control how YouTube localises its responses. YouTube uses two InnerTube context fields for this: hl (interface language) and gl (content region). All three classes validate input against the official ISO lists via pycountry, so typos raise a clear ValueError instead of silently producing broken requests.
Language
Language wraps a single ISO 639-1 two-letter language code and sets the hl field in every InnerTube request context.
Constructor
A valid ISO 639-1 two-letter language code (e.g.
"en", "uk", "de"). The code is normalised to lowercase on creation. An unrecognised code raises ValueError.Attributes
The validated, lowercase ISO 639-1 language code (e.g.
"en", "uk").Class methods
Coerces a raw ISO 639-1 string or an existing
Language instance into a Language. Returns the instance unchanged if it is already a Language.The language to coerce.
Examples
Country
Country wraps a single ISO 3166-1 alpha-2 two-letter country code and sets the gl field in every InnerTube request context.
Constructor
A valid ISO 3166-1 alpha-2 two-letter country code (e.g.
"US", "UA", "DE"). The code is normalised to uppercase on creation. An unrecognised code raises ValueError.Attributes
The validated, uppercase ISO 3166-1 alpha-2 country code (e.g.
"US", "UA").Class methods
Coerces a raw ISO 3166-1 alpha-2 string or an existing
Country instance into a Country. Returns the instance unchanged if it is already a Country.The country to coerce.
Examples
Locale
Locale bundles a Language and a Country into a single immutable value object. It is the object you pass to YouTube to localise all requests made through that client instance.
Constructor
The interface language. Accepts a
Language instance or a raw ISO 639-1 code string. Defaults to Language("en").The content region. Accepts a
Country instance or a raw ISO 3166-1 alpha-2 code string. Defaults to Country("US").Attributes
The validated
Language instance used for the hl context field.The validated
Country instance used for the gl context field.The value for the
Accept-Language HTTP header derived from this locale. Combines the language and country codes into a standard language tag with a plain-language fallback and a quality factor — for example, Language("uk") + Country("UA") produces "uk-UA,uk;q=0.9".Class methods
Builds a
Locale from optional language and country arguments, falling back to defaults ("en" / "US") for any argument that is None. Each argument is coerced via Language.of or Country.of.The interface language, or
None to use the default "en".The content region, or
None to use the default "US".Usage with YouTube
Pass a Locale to the YouTube constructor to localise all requests made through that client:
Validation behaviour
BothLanguage and Country are validated immediately on construction using pycountry. Passing an unrecognised code raises ValueError with a message indicating what was wrong and what form is expected: