wow#

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:
...     client.playable_classes.get(1).name
'Warrior'
class wow.AsyncClient(client_id: str | None = None, client_secret: str | None = None, *, access_token: str | None = None, region: Region | str = Region.US, locale: 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)[source]#

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 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)
Parameters:
  • client_id – App client id. Defaults to the BATTLENET_CLIENT_ID environment variable.

  • client_secret – App client secret. Defaults to BATTLENET_CLIENT_SECRET.

  • access_token – A token to send instead of fetching one with the app credentials, such as a user token with the wow.profile scope.

  • region – The API region to read.

  • locale – The language for names and descriptions. Defaults to the region’s main locale.

  • timeout – Seconds, or an httpx.Timeout, applied to every request.

  • max_retries – Retries for connection errors, timeouts, 408, 429 and 5xx responses. 0 disables retrying.

  • http_client – An httpx.AsyncClient to send requests through, for proxies, transports or caching. The caller keeps ownership and must close it.

  • base_url – Override the API host, for example to point at a mock server.

  • oauth_url – Override the OAuth host.

  • 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.

  • ValueError – locale, max_retries or access_token is invalid.

property region: Region#

The region this client reads.

property locale: Locale#

The locale names and descriptions come back in.

property static_version: str | None#

The build static-data requests are pinned to, or None for Battle.net’s current static namespace.

property account: AsyncAccount#

The authenticated user’s WoW Forever accounts and characters.

property achievement_categories: AsyncAchievementCategories#

The groups achievements are organized into.

property achievements: AsyncAchievements#

Achievements such as Explorer and Master of Alterac Valley.

property auctions: AsyncAuctions#

The auction houses Forever’s rulesets use in place of realm auction houses.

property characters: AsyncCharacters#

gear, stats, talents, professions and more.

Type:

Any character’s public profile

property creature_families: AsyncCreatureFamilies#

Pet families such as Bat and Wolf.

property creature_types: AsyncCreatureTypes#

Creature types such as Beast and Dragonkin.

property creatures: AsyncCreatures#

Creatures, Forest Spider included.

property guild_crests: AsyncGuildCrests#

The emblems, borders and colors guild crests use.

property guilds: AsyncGuilds#

Guilds and their rosters.

property item_appearances: AsyncItemAppearances#

The renders items share, and the slots and sets they group into.

property item_classes: AsyncItemClasses#

Item classes such as Weapon and Consumable.

property item_sets: AsyncItemSets#

Equipment sets.

property items: AsyncItems#

Items.

property media: AsyncMedia#

Media documents across every static type, searchable by tag.

property mounts: AsyncMounts#

Mounts.

property pets: AsyncPets#

Battle pet species.

property playable_classes: AsyncPlayableClasses#

Playable classes such as Warrior and Mage.

property playable_races: AsyncPlayableRaces#

Playable races such as Human and Orc.

property playable_specializations: AsyncPlayableSpecializations#

Class specializations such as Fury or Restoration.

property power_types: AsyncPowerTypes#

Power types such as Mana and Rage.

property professions: AsyncProfessions#

Professions such as Tailoring and Cooking.

property quest_areas: AsyncQuestAreas#

The zones quests take place in.

property quest_categories: AsyncQuestCategories#

Quest groupings such as Epic or Seasonal.

property quest_types: AsyncQuestTypes#

Quest kinds such as Elite, PvP or Raid.

property quests: AsyncQuests#

Individual quests.

property realms: AsyncRealms#

WoW Forever realms.

property recipes: AsyncRecipes#

Profession recipes.

property regions: AsyncRegions#

Battle.net API regions.

property reputation_factions: AsyncReputationFactions#

Reputation factions such as cities, tribes and armies.

property reputation_tiers: AsyncReputationTiers#

The standing levels a faction’s reputation can reach.

property rulesets: AsyncRulesets#

Rulesets such as Normal and PvP, which Forever has in place of realms.

property spells: AsyncSpells#

Spells, such as talents and abilities.

property talent_trees: AsyncTalentTrees#

Class and specialization talent trees.

property talents: AsyncTalents#

Individual talents across every class and specialization.

property titles: AsyncTitles#

Character titles such as Commander.

property toys: AsyncToys#

Toy-box toys.

with_options(*, region: Region | str | None = None, locale: 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[source]#

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.

Parameters:
  • region – Read another region. The locale follows the region unless one was set explicitly.

  • locale – Use another locale.

  • access_token – Authenticate as a user, for profile routes.

  • timeout – Change the request timeout.

  • max_retries – Change the retry budget.

  • static_version – Pin static-data requests to another build.

Raises:

ValueError – locale, max_retries or access_token is invalid.

async aclose() → None[source]#

Close the connection pool, unless it was passed in as http_client or this client is a copy.

async get(path: str, *, namespace: NamespaceKind | None = None, params: collections.abc.Mapping[str, str | int] | None = None) → APIResponse[source]#

GET any document, for routes without a typed method or links followed by hand.

Parameters:
  • path – A path such as /data/wow/playable-class/1, or a full href from a document’s links. Hrefs already carry their namespace.

  • namespace – The document family to read. Leave it out for hrefs.

  • params – Extra query parameters.

Raises:
  • ValueError – path is a URL on another host; the client never sends its token elsewhere.

  • APIStatusError – Battle.net answered with an error status.

  • APIConnectionError – No response arrived.

authorization_url(redirect_uri: str, *, state: str, scopes: str | collections.abc.Iterable[str] = ('wow.profile',)) → str[source]#

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 exchange_code().

Parameters:
  • redirect_uri – A redirect URL registered for the app.

  • state – An unguessable value tied to the user’s session, to stop cross-site request forgery.

  • scopes – Scopes to request, as one string or several. wow.profile unlocks the account profile; add openid for an ID token.

async exchange_code(code: str, redirect_uri: str) → OAuthToken[source]#

Trade an authorization code for the user’s access token.

Use the token with client.with_options(access_token=token.access_token).

Parameters:
  • code – The code query parameter Battle.net redirected back with.

  • redirect_uri – The same redirect_uri given to authorization_url().

Raises:
class wow.OAuthToken[source]#

An access token issued by oauth.battle.net.

Variables:
  • access_token – The bearer token to send to the API.

  • expires_at – When Battle.net stops accepting it.

  • scopes – The scopes it was granted; wow.profile is needed for profile routes.

  • token_type – Always bearer today.

  • sub – The Battle.net account id, for user tokens.

  • id_token – The OpenID Connect ID token, when openid was requested.

access_token: str#
expires_at: datetime.datetime#
scopes: frozenset[str]#
token_type: str = 'bearer'#
sub: str | None = None#
id_token: str | None = None#
expires_within(margin: datetime.timedelta) → bool[source]#

Whether the token expires within margin from now.

exception wow.APIConnectionError(message: str, *, request: httpx.Request)#

Bases: APIError

The request produced no usable response: DNS, TLS, a refused or reset connection, or a corrupt body.

exception wow.APIError(message: str, *, request: httpx.Request)#

Bases: WowError

A request to Battle.net failed.

Variables:

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.

request: httpx.Request#
exception wow.APIResponseValidationError(message: str, *, response: httpx.Response, error: msgspec.DecodeError)#

Bases: APIError

The response did not match the model it was parsed into.

Variables:

response – The response whose body failed validation.

response: httpx.Response#
exception wow.APIStatusError(message: str, *, response: httpx.Response, body: Any)#

Bases: APIError

Battle.net answered with a 4xx or 5xx status.

Variables:
  • response – The error response.

  • status_code – Its HTTP status.

  • body – The decoded JSON body, or the raw text when it is not JSON.

  • namespace – The battlenet-namespace header, which Battle.net sends only when it recognised the namespace.

response: httpx.Response#
status_code: int#
body: Any#
namespace: str | None#
exception wow.APITimeoutError(message: str, *, request: httpx.Request)#

Bases: APIConnectionError

The request timed out.

exception wow.AuthenticationError(message: str, *, response: httpx.Response, body: Any)#

Bases: APIStatusError

HTTP 401: the access token is missing, expired or revoked, or the client credentials were rejected.

exception wow.BadRequestError(message: str, *, response: httpx.Response, body: Any)#

Bases: APIStatusError

HTTP 400: a malformed request, such as an invalid search filter.

exception wow.InternalServerError(message: str, *, response: httpx.Response, body: Any)#

Bases: APIStatusError

HTTP 5xx: Battle.net failed, even after retrying.

exception wow.NotFoundError(message: str, *, response: httpx.Response, body: Any)#

Bases: APIStatusError

HTTP 404: no document at this path.

When 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.

exception wow.PermissionDeniedError(message: str, *, response: httpx.Response, body: Any)#

Bases: 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.

exception wow.RateLimitError(message: str, *, response: httpx.Response, body: Any)#

Bases: APIStatusError

HTTP 429: the client exceeded Battle.net’s request quota, even after retrying.

exception wow.WowError#

Bases: Exception

Base class for every error this package raises.

class wow.APIResponse(http_response: httpx.Response)[source]#

A successful response from 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.

http_response: httpx.Response#

The underlying httpx response.

property status_code: int#

The HTTP status code.

property url: str#

The URL that was requested, including query parameters.

property headers: httpx.Headers#

The response headers.

property namespace: str | None#

The namespace Battle.net resolved, such as static-1.60.1_70399-forever-us for static-forever-us.

property last_modified: datetime.datetime | None#

When the document last changed, from the Last-Modified header.

json() → Any[source]#

Decode the body as JSON.

parse[ModelT: msgspec.Struct](model: type[ModelT]) → ModelT[source]#

Validate the body into model.

Raises:

APIResponseValidationError – The body does not match model.

class wow.Client(client_id: str | None = None, client_secret: str | None = None, *, access_token: str | None = None, region: Region | str = Region.US, locale: 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)[source]#

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 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)
Parameters:
  • client_id – App client id. Defaults to the BATTLENET_CLIENT_ID environment variable.

  • client_secret – App client secret. Defaults to BATTLENET_CLIENT_SECRET.

  • access_token – A token to send instead of fetching one with the app credentials, such as a user token with the wow.profile scope.

  • region – The API region to read.

  • locale – The language for names and descriptions. Defaults to the region’s main locale.

  • timeout – Seconds, or an httpx.Timeout, applied to every request.

  • max_retries – Retries for connection errors, timeouts, 408, 429 and 5xx responses. 0 disables retrying.

  • http_client – An httpx.Client to send requests through, for proxies, transports or caching. The caller keeps ownership and must close it.

  • base_url – Override the API host, for example to point at a mock server.

  • oauth_url – Override the OAuth host.

  • 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.

  • ValueError – locale, max_retries or access_token is invalid.

property region: Region#

The region this client reads.

property locale: Locale#

The locale names and descriptions come back in.

property static_version: str | None#

The build static-data requests are pinned to, or None for Battle.net’s current static namespace.

property account: Account#

The authenticated user’s WoW Forever accounts and characters.

property achievement_categories: AchievementCategories#

The groups achievements are organized into.

property achievements: Achievements#

Achievements such as Explorer and Master of Alterac Valley.

property auctions: Auctions#

The auction houses Forever’s rulesets use in place of realm auction houses.

property characters: Characters#

gear, stats, talents, professions and more.

Type:

Any character’s public profile

property creature_families: CreatureFamilies#

Pet families such as Bat and Wolf.

property creature_types: CreatureTypes#

Creature types such as Beast and Dragonkin.

property creatures: Creatures#

Creatures, Forest Spider included.

property guild_crests: GuildCrests#

The emblems, borders and colors guild crests use.

property guilds: Guilds#

Guilds and their rosters.

property item_appearances: ItemAppearances#

The renders items share, and the slots and sets they group into.

property item_classes: ItemClasses#

Item classes such as Weapon and Consumable.

property item_sets: ItemSets#

Equipment sets.

property items: Items#

Items.

property media: Media#

Media documents across every static type, searchable by tag.

property mounts: Mounts#

Mounts.

property pets: Pets#

Battle pet species.

property playable_classes: PlayableClasses#

Playable classes such as Warrior and Mage.

property playable_races: PlayableRaces#

Playable races such as Human and Orc.

property playable_specializations: PlayableSpecializations#

Class specializations such as Fury or Restoration.

property power_types: PowerTypes#

Power types such as Mana and Rage.

property professions: Professions#

Professions such as Tailoring and Cooking.

property quest_areas: QuestAreas#

The zones quests take place in.

property quest_categories: QuestCategories#

Quest groupings such as Epic or Seasonal.

property quest_types: QuestTypes#

Quest kinds such as Elite, PvP or Raid.

property quests: Quests#

Individual quests.

property realms: Realms#

WoW Forever realms.

property recipes: Recipes#

Profession recipes.

property regions: Regions#

Battle.net API regions.

property reputation_factions: ReputationFactions#

Reputation factions such as cities, tribes and armies.

property reputation_tiers: ReputationTiers#

The standing levels a faction’s reputation can reach.

property rulesets: Rulesets#

Rulesets such as Normal and PvP, which Forever has in place of realms.

property spells: Spells#

Spells, such as talents and abilities.

property talent_trees: TalentTrees#

Class and specialization talent trees.

property talents: Talents#

Individual talents across every class and specialization.

property titles: Titles#

Character titles such as Commander.

property toys: Toys#

Toy-box toys.

with_options(*, region: Region | str | None = None, locale: 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[source]#

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.

Parameters:
  • region – Read another region. The locale follows the region unless one was set explicitly.

  • locale – Use another locale.

  • access_token – Authenticate as a user, for profile routes.

  • timeout – Change the request timeout.

  • max_retries – Change the retry budget.

  • static_version – Pin static-data requests to another build.

Raises:

ValueError – locale, max_retries or access_token is invalid.

close() → None[source]#

Close the connection pool, unless it was passed in as http_client or this client is a copy.

get(path: str, *, namespace: NamespaceKind | None = None, params: collections.abc.Mapping[str, str | int] | None = None) → APIResponse[source]#

GET any document, for routes without a typed method or links followed by hand.

Parameters:
  • path – A path such as /data/wow/playable-class/1, or a full href from a document’s links. Hrefs already carry their namespace.

  • namespace – The document family to read. Leave it out for hrefs.

  • params – Extra query parameters.

Raises:
  • ValueError – path is a URL on another host; the client never sends its token elsewhere.

  • APIStatusError – Battle.net answered with an error status.

  • APIConnectionError – No response arrived.

authorization_url(redirect_uri: str, *, state: str, scopes: str | collections.abc.Iterable[str] = ('wow.profile',)) → str[source]#

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 exchange_code().

Parameters:
  • redirect_uri – A redirect URL registered for the app.

  • state – An unguessable value tied to the user’s session, to stop cross-site request forgery.

  • scopes – Scopes to request, as one string or several. wow.profile unlocks the account profile; add openid for an ID token.

exchange_code(code: str, redirect_uri: str) → OAuthToken[source]#

Trade an authorization code for the user’s access token.

Use the token with client.with_options(access_token=token.access_token).

Parameters:
  • code – The code query parameter Battle.net redirected back with.

  • redirect_uri – The same redirect_uri given to authorization_url().

Raises:
type wow.Locale = 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.

type wow.NamespaceKind = 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}.

class wow.Region[source]#

Bases: 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.

US = 'us'#
EU = 'eu'#
KR = 'kr'#
TW = 'tw'#