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_IDenvironment 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.profilescope.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.
0disables retrying.http_client – An
httpx.AsyncClientto 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_retriesoraccess_tokenis invalid.
- property static_version: str | None#
The build static-data requests are pinned to, or
Nonefor 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 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.
- 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_retriesoraccess_tokenis invalid.
- async aclose() None[source]#
Close the connection pool, unless it was passed in as
http_clientor 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 fullhreffrom 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 –
pathis 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_uriwithcodeandstatequery parameters. Checkstatematches, then passcodetoexchange_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.profileunlocks the account profile; addopenidfor 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
codequery parameter Battle.net redirected back with.redirect_uri – The same
redirect_urigiven toauthorization_url().
- Raises:
AuthenticationError – The app credentials were rejected.
BadRequestError – The code is invalid, expired or already used, or
redirect_uridoes not match.
- 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.profileis needed for profile routes.token_type – Always
bearertoday.sub – The Battle.net account id, for user tokens.
id_token – The OpenID Connect ID token, when
openidwas requested.
- access_token: str#
- expires_at: datetime.datetime#
- scopes: frozenset[str]#
- token_type: str = 'bearer'#
- sub: str | None = None#
- id_token: str | None = None#
- exception wow.APIConnectionError(message: str, *, request: httpx.Request)#
Bases:
APIErrorThe 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:
WowErrorA request to Battle.net failed.
- Variables:
request – The request that failed. Its
Authorizationheader holds the live bearer token:reprhides it, but do not log or serializerequest.headerswholesale.
- request: httpx.Request#
- exception wow.APIResponseValidationError(message: str, *, response: httpx.Response, error: msgspec.DecodeError)#
Bases:
APIErrorThe 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:
APIErrorBattle.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-namespaceheader, 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:
APIConnectionErrorThe request timed out.
- exception wow.AuthenticationError(message: str, *, response: httpx.Response, body: Any)#
Bases:
APIStatusErrorHTTP 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:
APIStatusErrorHTTP 400: a malformed request, such as an invalid search filter.
- exception wow.InternalServerError(message: str, *, response: httpx.Response, body: Any)#
Bases:
APIStatusErrorHTTP 5xx: Battle.net failed, even after retrying.
- exception wow.NotFoundError(message: str, *, response: httpx.Response, body: Any)#
Bases:
APIStatusErrorHTTP 404: no document at this path.
When
namespaceis 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:
APIStatusErrorHTTP 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.profilescope.
- exception wow.RateLimitError(message: str, *, response: httpx.Response, body: Any)#
Bases:
APIStatusErrorHTTP 429: the client exceeded Battle.net’s request quota, even after retrying.
- exception wow.WowError#
Bases:
ExceptionBase 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
httpxresponse.
- 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-usforstatic-forever-us.
- property last_modified: datetime.datetime | None#
When the document last changed, from the
Last-Modifiedheader.
- 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_IDenvironment 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.profilescope.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.
0disables retrying.http_client – An
httpx.Clientto 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_retriesoraccess_tokenis invalid.
- property static_version: str | None#
The build static-data requests are pinned to, or
Nonefor Battle.net’s current static namespace.
- 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 guild_crests: GuildCrests#
The emblems, borders and colors guild crests use.
- 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 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 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 talent_trees: TalentTrees#
Class and specialization talent trees.
- 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_retriesoraccess_tokenis invalid.
- close() None[source]#
Close the connection pool, unless it was passed in as
http_clientor 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 fullhreffrom 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 –
pathis 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_uriwithcodeandstatequery parameters. Checkstatematches, then passcodetoexchange_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.profileunlocks the account profile; addopenidfor 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
codequery parameter Battle.net redirected back with.redirect_uri – The same
redirect_urigiven toauthorization_url().
- Raises:
AuthenticationError – The app credentials were rejected.
BadRequestError – The code is invalid, expired or already used, or
redirect_uridoes not match.
- 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
localequery parameter.
- type wow.NamespaceKind = Literal['static', 'dynamic', 'profile']#
Which family of documents a request reads.
staticholds game data that only changes with patches,dynamicholds live state such as realms, andprofileholds player data. The wire namespace is{kind}-forever-{region}.