wow === .. py:module:: wow .. autoapi-nested-parse:: Typed sync and async client for the World of Warcraft: Forever Battle.net API. >>> from wow import Client >>> with Client(client_id="...", client_secret="...") as client: # doctest: +SKIP ... client.playable_classes.get(1).name 'Warrior' .. py:class:: AsyncClient(client_id: str | None = None, client_secret: str | None = None, *, access_token: str | None = None, region: wow._types.Region | str = Region.US, locale: wow._types.Locale | None = None, timeout: float | httpx.Timeout = DEFAULT_TIMEOUT, max_retries: int = DEFAULT_MAX_RETRIES, http_client: httpx.AsyncClient | None = None, base_url: str | None = None, oauth_url: str = OAUTH_URL, static_version: str | None = None) Async client for the World of Warcraft: Forever API. Game data needs app credentials from https://develop.battle.net; the client trades them for an access token and refreshes it before it expires. Profile routes need a user's token instead, from :meth:`exchange_code`. Use one client for the life of your program and close it when done; it is a context manager:: async with AsyncClient(region="eu") as client: druid = await client.playable_classes.get(11) :param client_id: App client id. Defaults to the ``BATTLENET_CLIENT_ID`` environment variable. :param client_secret: App client secret. Defaults to ``BATTLENET_CLIENT_SECRET``. :param access_token: A token to send instead of fetching one with the app credentials, such as a user token with the ``wow.profile`` scope. :param region: The API region to read. :param locale: The language for names and descriptions. Defaults to the region's main locale. :param timeout: Seconds, or an ``httpx.Timeout``, applied to every request. :param max_retries: Retries for connection errors, timeouts, 408, 429 and 5xx responses. ``0`` disables retrying. :param http_client: An ``httpx.AsyncClient`` to send requests through, for proxies, transports or caching. The caller keeps ownership and must close it. :param base_url: Override the API host, for example to point at a mock server. :param oauth_url: Override the OAuth host. :param static_version: Pin static-data requests (playable classes, items, talents and the rest of game data that only changes with patches) to one build, such as ``"1.60.1_70399"``, instead of Battle.net's current static namespace. Dynamic and profile requests are unaffected. :raises WowError: Neither app credentials nor an access token were given. :raises ValueError: ``locale``, ``max_retries`` or ``access_token`` is invalid. .. py:property:: region :type: wow._types.Region The region this client reads. .. py:property:: locale :type: wow._types.Locale The locale names and descriptions come back in. .. py:property:: static_version :type: str | None The build static-data requests are pinned to, or ``None`` for Battle.net's current static namespace. .. py:property:: account :type: wow._async.resources.account.AsyncAccount The authenticated user's WoW Forever accounts and characters. .. py:property:: achievement_categories :type: wow._async.resources.achievement.AsyncAchievementCategories The groups achievements are organized into. .. py:property:: achievements :type: wow._async.resources.achievement.AsyncAchievements Achievements such as Explorer and Master of Alterac Valley. .. py:property:: auctions :type: wow._async.resources.auction.AsyncAuctions The auction houses Forever's rulesets use in place of realm auction houses. .. py:property:: characters :type: wow._async.resources.character.AsyncCharacters gear, stats, talents, professions and more. :type: Any character's public profile .. py:property:: creature_families :type: wow._async.resources.creature.AsyncCreatureFamilies Pet families such as Bat and Wolf. .. py:property:: creature_types :type: wow._async.resources.creature.AsyncCreatureTypes Creature types such as Beast and Dragonkin. .. py:property:: creatures :type: wow._async.resources.creature.AsyncCreatures Creatures, Forest Spider included. .. py:property:: guild_crests :type: wow._async.resources.guild_crest.AsyncGuildCrests The emblems, borders and colors guild crests use. .. py:property:: guilds :type: wow._async.resources.guild.AsyncGuilds Guilds and their rosters. .. py:property:: item_appearances :type: wow._async.resources.item_appearance.AsyncItemAppearances The renders items share, and the slots and sets they group into. .. py:property:: item_classes :type: wow._async.resources.item.AsyncItemClasses Item classes such as Weapon and Consumable. .. py:property:: item_sets :type: wow._async.resources.item.AsyncItemSets Equipment sets. .. py:property:: items :type: wow._async.resources.item.AsyncItems Items. .. py:property:: media :type: wow._async.resources.media.AsyncMedia Media documents across every static type, searchable by tag. .. py:property:: mounts :type: wow._async.resources.mount.AsyncMounts Mounts. .. py:property:: pets :type: wow._async.resources.pet.AsyncPets Battle pet species. .. py:property:: playable_classes :type: wow._async.resources.playable_class.AsyncPlayableClasses Playable classes such as Warrior and Mage. .. py:property:: playable_races :type: wow._async.resources.playable_race.AsyncPlayableRaces Playable races such as Human and Orc. .. py:property:: playable_specializations :type: wow._async.resources.playable_specialization.AsyncPlayableSpecializations Class specializations such as Fury or Restoration. .. py:property:: power_types :type: wow._async.resources.power_type.AsyncPowerTypes Power types such as Mana and Rage. .. py:property:: professions :type: wow._async.resources.profession.AsyncProfessions Professions such as Tailoring and Cooking. .. py:property:: quest_areas :type: wow._async.resources.quest.AsyncQuestAreas The zones quests take place in. .. py:property:: quest_categories :type: wow._async.resources.quest.AsyncQuestCategories Quest groupings such as Epic or Seasonal. .. py:property:: quest_types :type: wow._async.resources.quest.AsyncQuestTypes Quest kinds such as Elite, PvP or Raid. .. py:property:: quests :type: wow._async.resources.quest.AsyncQuests Individual quests. .. py:property:: realms :type: wow._async.resources.realm.AsyncRealms WoW Forever realms. .. py:property:: recipes :type: wow._async.resources.recipe.AsyncRecipes Profession recipes. .. py:property:: regions :type: wow._async.resources.region.AsyncRegions Battle.net API regions. .. py:property:: reputation_factions :type: wow._async.resources.reputation.AsyncReputationFactions Reputation factions such as cities, tribes and armies. .. py:property:: reputation_tiers :type: wow._async.resources.reputation.AsyncReputationTiers The standing levels a faction's reputation can reach. .. py:property:: rulesets :type: wow._async.resources.ruleset.AsyncRulesets Rulesets such as Normal and PvP, which Forever has in place of realms. .. py:property:: spells :type: wow._async.resources.spell.AsyncSpells Spells, such as talents and abilities. .. py:property:: talent_trees :type: wow._async.resources.talent.AsyncTalentTrees Class and specialization talent trees. .. py:property:: talents :type: wow._async.resources.talent.AsyncTalents Individual talents across every class and specialization. .. py:property:: titles :type: wow._async.resources.title.AsyncTitles Character titles such as Commander. .. py:property:: toys :type: wow._async.resources.toy.AsyncToys Toy-box toys. .. py:method:: with_options(*, region: wow._types.Region | str | None = None, locale: wow._types.Locale | None = None, access_token: str | None = None, timeout: float | httpx.Timeout | None = None, max_retries: int | None = None, static_version: str | None = None) -> Self Return a client with some settings changed. The copy shares the connection pool and the cached app token, so it is cheap; make one per region, locale or user token as needed. Only the original client closes the pool. :param region: Read another region. The locale follows the region unless one was set explicitly. :param locale: Use another locale. :param access_token: Authenticate as a user, for profile routes. :param timeout: Change the request timeout. :param max_retries: Change the retry budget. :param static_version: Pin static-data requests to another build. :raises ValueError: ``locale``, ``max_retries`` or ``access_token`` is invalid. .. py:method:: aclose() -> None :async: Close the connection pool, unless it was passed in as ``http_client`` or this client is a copy. .. py:method:: get(path: str, *, namespace: wow._types.NamespaceKind | None = None, params: collections.abc.Mapping[str, str | int] | None = None) -> wow._response.APIResponse :async: GET any document, for routes without a typed method or links followed by hand. :param path: A path such as ``/data/wow/playable-class/1``, or a full ``href`` from a document's links. Hrefs already carry their namespace. :param namespace: The document family to read. Leave it out for hrefs. :param params: Extra query parameters. :raises ValueError: ``path`` is a URL on another host; the client never sends its token elsewhere. :raises APIStatusError: Battle.net answered with an error status. :raises APIConnectionError: No response arrived. .. py:method:: authorization_url(redirect_uri: str, *, state: str, scopes: str | collections.abc.Iterable[str] = ('wow.profile', )) -> str Build the Battle.net login URL for the authorization code flow. Send the user here; Battle.net redirects back to ``redirect_uri`` with ``code`` and ``state`` query parameters. Check ``state`` matches, then pass ``code`` to :meth:`exchange_code`. :param redirect_uri: A redirect URL registered for the app. :param state: An unguessable value tied to the user's session, to stop cross-site request forgery. :param scopes: Scopes to request, as one string or several. ``wow.profile`` unlocks the account profile; add ``openid`` for an ID token. .. py:method:: exchange_code(code: str, redirect_uri: str) -> wow._base.OAuthToken :async: Trade an authorization code for the user's access token. Use the token with ``client.with_options(access_token=token.access_token)``. :param code: The ``code`` query parameter Battle.net redirected back with. :param redirect_uri: The same ``redirect_uri`` given to :meth:`authorization_url`. :raises AuthenticationError: The app credentials were rejected. :raises BadRequestError: The code is invalid, expired or already used, or ``redirect_uri`` does not match. .. py:class:: OAuthToken An access token issued by ``oauth.battle.net``. :ivar access_token: The bearer token to send to the API. :ivar expires_at: When Battle.net stops accepting it. :ivar scopes: The scopes it was granted; ``wow.profile`` is needed for profile routes. :ivar token_type: Always ``bearer`` today. :ivar sub: The Battle.net account id, for user tokens. :ivar id_token: The OpenID Connect ID token, when ``openid`` was requested. .. py:attribute:: access_token :type: str .. py:attribute:: expires_at :type: datetime.datetime .. py:attribute:: scopes :type: frozenset[str] .. py:attribute:: token_type :type: str :value: 'bearer' .. py:attribute:: sub :type: str | None :value: None .. py:attribute:: id_token :type: str | None :value: None .. py:method:: expires_within(margin: datetime.timedelta) -> bool Whether the token expires within ``margin`` from now. .. py:exception:: APIConnectionError(message: str, *, request: httpx.Request) Bases: :py:obj:`APIError` The request produced no usable response: DNS, TLS, a refused or reset connection, or a corrupt body. .. py:exception:: APIError(message: str, *, request: httpx.Request) Bases: :py:obj:`WowError` A request to Battle.net failed. :ivar request: The request that failed. Its ``Authorization`` header holds the live bearer token: ``repr`` hides it, but do not log or serialize ``request.headers`` wholesale. .. py:attribute:: request :type: httpx.Request .. py:exception:: APIResponseValidationError(message: str, *, response: httpx.Response, error: msgspec.DecodeError) Bases: :py:obj:`APIError` The response did not match the model it was parsed into. :ivar response: The response whose body failed validation. .. py:attribute:: response :type: httpx.Response .. py:exception:: APIStatusError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIError` Battle.net answered with a 4xx or 5xx status. :ivar response: The error response. :ivar status_code: Its HTTP status. :ivar body: The decoded JSON body, or the raw text when it is not JSON. :ivar namespace: The ``battlenet-namespace`` header, which Battle.net sends only when it recognised the namespace. .. py:attribute:: response :type: httpx.Response .. py:attribute:: status_code :type: int .. py:attribute:: body :type: Any .. py:attribute:: namespace :type: str | None .. py:exception:: APITimeoutError(message: str, *, request: httpx.Request) Bases: :py:obj:`APIConnectionError` The request timed out. .. py:exception:: AuthenticationError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIStatusError` HTTP 401: the access token is missing, expired or revoked, or the client credentials were rejected. .. py:exception:: BadRequestError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIStatusError` HTTP 400: a malformed request, such as an invalid search filter. .. py:exception:: InternalServerError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIStatusError` HTTP 5xx: Battle.net failed, even after retrying. .. py:exception:: NotFoundError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIStatusError` HTTP 404: no document at this path. When :attr:`namespace` is set the namespace exists and the document does not, which is how much of WoW Forever looks while Blizzard is still publishing it. .. py:exception:: PermissionDeniedError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIStatusError` HTTP 403: the namespace does not exist, or the token lacks the scope the route needs. Profile routes such as the account profile need a user token with the ``wow.profile`` scope. .. py:exception:: RateLimitError(message: str, *, response: httpx.Response, body: Any) Bases: :py:obj:`APIStatusError` HTTP 429: the client exceeded Battle.net's request quota, even after retrying. .. py:exception:: WowError Bases: :py:obj:`Exception` Base class for every error this package raises. .. py:class:: APIResponse(http_response: httpx.Response) A successful response from :meth:`Client.get `. Typed resource methods return models directly; this wrapper is for headers, documents the package has no model for yet, and links followed by hand. .. py:attribute:: http_response :type: httpx.Response The underlying ``httpx`` response. .. py:property:: status_code :type: int The HTTP status code. .. py:property:: url :type: str The URL that was requested, including query parameters. .. py:property:: headers :type: httpx.Headers The response headers. .. py:property:: namespace :type: str | None The namespace Battle.net resolved, such as ``static-1.60.1_70399-forever-us`` for ``static-forever-us``. .. py:property:: last_modified :type: datetime.datetime | None When the document last changed, from the ``Last-Modified`` header. .. py:method:: json() -> Any Decode the body as JSON. .. py:method:: parse[ModelT: msgspec.Struct](model: type[ModelT]) -> ModelT Validate the body into ``model``. :raises APIResponseValidationError: The body does not match ``model``. .. py:class:: Client(client_id: str | None = None, client_secret: str | None = None, *, access_token: str | None = None, region: wow._types.Region | str = Region.US, locale: wow._types.Locale | None = None, timeout: float | httpx.Timeout = DEFAULT_TIMEOUT, max_retries: int = DEFAULT_MAX_RETRIES, http_client: httpx.Client | None = None, base_url: str | None = None, oauth_url: str = OAUTH_URL, static_version: str | None = None) Client for the World of Warcraft: Forever API. Game data needs app credentials from https://develop.battle.net; the client trades them for an access token and refreshes it before it expires. Profile routes need a user's token instead, from :meth:`exchange_code`. Use one client for the life of your program and close it when done; it is a context manager:: with Client(region="eu") as client: druid = client.playable_classes.get(11) :param client_id: App client id. Defaults to the ``BATTLENET_CLIENT_ID`` environment variable. :param client_secret: App client secret. Defaults to ``BATTLENET_CLIENT_SECRET``. :param access_token: A token to send instead of fetching one with the app credentials, such as a user token with the ``wow.profile`` scope. :param region: The API region to read. :param locale: The language for names and descriptions. Defaults to the region's main locale. :param timeout: Seconds, or an ``httpx.Timeout``, applied to every request. :param max_retries: Retries for connection errors, timeouts, 408, 429 and 5xx responses. ``0`` disables retrying. :param http_client: An ``httpx.Client`` to send requests through, for proxies, transports or caching. The caller keeps ownership and must close it. :param base_url: Override the API host, for example to point at a mock server. :param oauth_url: Override the OAuth host. :param static_version: Pin static-data requests (playable classes, items, talents and the rest of game data that only changes with patches) to one build, such as ``"1.60.1_70399"``, instead of Battle.net's current static namespace. Dynamic and profile requests are unaffected. :raises WowError: Neither app credentials nor an access token were given. :raises ValueError: ``locale``, ``max_retries`` or ``access_token`` is invalid. .. py:property:: region :type: wow._types.Region The region this client reads. .. py:property:: locale :type: wow._types.Locale The locale names and descriptions come back in. .. py:property:: static_version :type: str | None The build static-data requests are pinned to, or ``None`` for Battle.net's current static namespace. .. py:property:: account :type: wow._sync.resources.account.Account The authenticated user's WoW Forever accounts and characters. .. py:property:: achievement_categories :type: wow._sync.resources.achievement.AchievementCategories The groups achievements are organized into. .. py:property:: achievements :type: wow._sync.resources.achievement.Achievements Achievements such as Explorer and Master of Alterac Valley. .. py:property:: auctions :type: wow._sync.resources.auction.Auctions The auction houses Forever's rulesets use in place of realm auction houses. .. py:property:: characters :type: wow._sync.resources.character.Characters gear, stats, talents, professions and more. :type: Any character's public profile .. py:property:: creature_families :type: wow._sync.resources.creature.CreatureFamilies Pet families such as Bat and Wolf. .. py:property:: creature_types :type: wow._sync.resources.creature.CreatureTypes Creature types such as Beast and Dragonkin. .. py:property:: creatures :type: wow._sync.resources.creature.Creatures Creatures, Forest Spider included. .. py:property:: guild_crests :type: wow._sync.resources.guild_crest.GuildCrests The emblems, borders and colors guild crests use. .. py:property:: guilds :type: wow._sync.resources.guild.Guilds Guilds and their rosters. .. py:property:: item_appearances :type: wow._sync.resources.item_appearance.ItemAppearances The renders items share, and the slots and sets they group into. .. py:property:: item_classes :type: wow._sync.resources.item.ItemClasses Item classes such as Weapon and Consumable. .. py:property:: item_sets :type: wow._sync.resources.item.ItemSets Equipment sets. .. py:property:: items :type: wow._sync.resources.item.Items Items. .. py:property:: media :type: wow._sync.resources.media.Media Media documents across every static type, searchable by tag. .. py:property:: mounts :type: wow._sync.resources.mount.Mounts Mounts. .. py:property:: pets :type: wow._sync.resources.pet.Pets Battle pet species. .. py:property:: playable_classes :type: wow._sync.resources.playable_class.PlayableClasses Playable classes such as Warrior and Mage. .. py:property:: playable_races :type: wow._sync.resources.playable_race.PlayableRaces Playable races such as Human and Orc. .. py:property:: playable_specializations :type: wow._sync.resources.playable_specialization.PlayableSpecializations Class specializations such as Fury or Restoration. .. py:property:: power_types :type: wow._sync.resources.power_type.PowerTypes Power types such as Mana and Rage. .. py:property:: professions :type: wow._sync.resources.profession.Professions Professions such as Tailoring and Cooking. .. py:property:: quest_areas :type: wow._sync.resources.quest.QuestAreas The zones quests take place in. .. py:property:: quest_categories :type: wow._sync.resources.quest.QuestCategories Quest groupings such as Epic or Seasonal. .. py:property:: quest_types :type: wow._sync.resources.quest.QuestTypes Quest kinds such as Elite, PvP or Raid. .. py:property:: quests :type: wow._sync.resources.quest.Quests Individual quests. .. py:property:: realms :type: wow._sync.resources.realm.Realms WoW Forever realms. .. py:property:: recipes :type: wow._sync.resources.recipe.Recipes Profession recipes. .. py:property:: regions :type: wow._sync.resources.region.Regions Battle.net API regions. .. py:property:: reputation_factions :type: wow._sync.resources.reputation.ReputationFactions Reputation factions such as cities, tribes and armies. .. py:property:: reputation_tiers :type: wow._sync.resources.reputation.ReputationTiers The standing levels a faction's reputation can reach. .. py:property:: rulesets :type: wow._sync.resources.ruleset.Rulesets Rulesets such as Normal and PvP, which Forever has in place of realms. .. py:property:: spells :type: wow._sync.resources.spell.Spells Spells, such as talents and abilities. .. py:property:: talent_trees :type: wow._sync.resources.talent.TalentTrees Class and specialization talent trees. .. py:property:: talents :type: wow._sync.resources.talent.Talents Individual talents across every class and specialization. .. py:property:: titles :type: wow._sync.resources.title.Titles Character titles such as Commander. .. py:property:: toys :type: wow._sync.resources.toy.Toys Toy-box toys. .. py:method:: with_options(*, region: wow._types.Region | str | None = None, locale: wow._types.Locale | None = None, access_token: str | None = None, timeout: float | httpx.Timeout | None = None, max_retries: int | None = None, static_version: str | None = None) -> Self Return a client with some settings changed. The copy shares the connection pool and the cached app token, so it is cheap; make one per region, locale or user token as needed. Only the original client closes the pool. :param region: Read another region. The locale follows the region unless one was set explicitly. :param locale: Use another locale. :param access_token: Authenticate as a user, for profile routes. :param timeout: Change the request timeout. :param max_retries: Change the retry budget. :param static_version: Pin static-data requests to another build. :raises ValueError: ``locale``, ``max_retries`` or ``access_token`` is invalid. .. py:method:: close() -> None Close the connection pool, unless it was passed in as ``http_client`` or this client is a copy. .. py:method:: get(path: str, *, namespace: wow._types.NamespaceKind | None = None, params: collections.abc.Mapping[str, str | int] | None = None) -> wow._response.APIResponse GET any document, for routes without a typed method or links followed by hand. :param path: A path such as ``/data/wow/playable-class/1``, or a full ``href`` from a document's links. Hrefs already carry their namespace. :param namespace: The document family to read. Leave it out for hrefs. :param params: Extra query parameters. :raises ValueError: ``path`` is a URL on another host; the client never sends its token elsewhere. :raises APIStatusError: Battle.net answered with an error status. :raises APIConnectionError: No response arrived. .. py:method:: authorization_url(redirect_uri: str, *, state: str, scopes: str | collections.abc.Iterable[str] = ('wow.profile', )) -> str Build the Battle.net login URL for the authorization code flow. Send the user here; Battle.net redirects back to ``redirect_uri`` with ``code`` and ``state`` query parameters. Check ``state`` matches, then pass ``code`` to :meth:`exchange_code`. :param redirect_uri: A redirect URL registered for the app. :param state: An unguessable value tied to the user's session, to stop cross-site request forgery. :param scopes: Scopes to request, as one string or several. ``wow.profile`` unlocks the account profile; add ``openid`` for an ID token. .. py:method:: exchange_code(code: str, redirect_uri: str) -> wow._base.OAuthToken Trade an authorization code for the user's access token. Use the token with ``client.with_options(access_token=token.access_token)``. :param code: The ``code`` query parameter Battle.net redirected back with. :param redirect_uri: The same ``redirect_uri`` given to :meth:`authorization_url`. :raises AuthenticationError: The app credentials were rejected. :raises BadRequestError: The code is invalid, expired or already used, or ``redirect_uri`` does not match. .. py:type:: Locale :canonical: Literal['en_US', 'es_MX', 'pt_BR', 'de_DE', 'en_GB', 'es_ES', 'fr_FR', 'it_IT', 'ru_RU', 'ko_KR', 'zh_TW', 'zh_CN'] A locale accepted by the ``locale`` query parameter. .. py:type:: NamespaceKind :canonical: Literal['static', 'dynamic', 'profile'] Which family of documents a request reads. ``static`` holds game data that only changes with patches, ``dynamic`` holds live state such as realms, and ``profile`` holds player data. The wire namespace is ``{kind}-forever-{region}``. .. py:class:: Region Bases: :py:obj:`enum.StrEnum` A Battle.net API region; each has its own host and its own namespaces. China is absent on purpose: it runs on a separate gateway with separate developer accounts, and WoW Forever has not been verified there. .. py:attribute:: US :value: 'us' .. py:attribute:: EU :value: 'eu' .. py:attribute:: KR :value: 'kr' .. py:attribute:: TW :value: 'tw'