webapi¶
WebAPI provides a thin wrapper over Steam’s Web API
It is very friendly to exploration and prototyping when using ipython, notebooks or similar.
The key will determine what WebAPI interfaces and methods are available.
Note
Some endpoints don’t require a key
Currently the WebAPI can be accessed via one of two API hosts. See APIHost.
Example code:
>>> api = WebAPI(key)
>>> api.call('ISteamUser.ResolveVanityURL', vanityurl="valve", url_type=2)
>>> api.ISteamUser.ResolveVanityURL(vanityurl="valve", url_type=2)
>>> api.ISteamUser.ResolveVanityURL_v1(vanityurl="valve", url_type=2)
{'response': {'steamid': '103582791429521412', 'success': 1}}
All globals params (key, https, format, raw) can be specified on per call basis.
>>> print a.ISteamUser.ResolveVanityURL(format='vdf', raw=True, vanityurl="valve", url_type=2)
"response"
{
"steamid" "103582791429521412"
"success" "1"
}
-
class
steam.webapi.APIHost¶ Enum of currently available API hosts.
-
Public= 'api.steampowered.com'¶ available over HTTP (port 80) and HTTPS (port 443)
-
Partner= 'partner.steam-api.com'¶ available over HTTPS (port 443) only
Note
Key is required for every request. If not supplied you will get HTTP 403.
-
-
class
steam.webapi.WebAPI(key, format='json', raw=False, https=True, http_timeout=30, apihost='api.steampowered.com', auto_load_interfaces=True)¶ Steam WebAPI wrapper
Note
Interfaces and methods are populated automatically from Steam WebAPI.
Parameters: - key (
str) – api key from https://steamcommunity.com/dev/apikey - format (
str) – response format, either (json,vdf, orxml) only whenraw=False - raw (class:bool) – return raw response
- https (
bool) – usehttps - http_timeout (
int) – HTTP timeout in seconds - apihost (
str) – api hostname, seeAPIHost - auto_load_interfaces (
bool) – load interfaces from the Steam WebAPI
These can be specified per method call for one off calls
-
key= None¶ api key
-
format= 'json'¶ format (
json,vdf, orxml)
-
raw= False¶ return raw reponse or parse
-
https= True¶ use https or not
-
http_timeout= 30¶ HTTP timeout in seconds
-
apihost= 'api.steampowered.com'¶ ..versionadded:: 0.8.3 apihost hostname
-
interfaces= []¶ list of all interfaces
-
session= None¶ requests.Sessionfrommake_requests_session()
-
fetch_interfaces()¶ Returns a dict with the response from
GetSupportedAPIListReturns: dictof all interfaces and methodsThe returned value can passed to
load_interfaces()
-
load_interfaces(interfaces_dict)¶ Populates the namespace under the instance
- key (
-
class
steam.webapi.WebAPIInterface(interface_dict, parent)¶
-
class
steam.webapi.WebAPIMethod(method_dict, parent)¶
-
steam.webapi.webapi_request(url, method='GET', caller=None, session=None, params=None)¶ Low level function for calling Steam’s WebAPI
Changed in version 0.8.3.
Parameters: - url (
str) – request url (e.g.https://api.steampowered.com/A/B/v001/) - method (
str) – HTTP method (GET or POST) - caller – caller reference, caller.last_response is set to the last response
- params (
dict) – dict of WebAPI and endpoint specific params - session (
requests.Session) – an instance requests session, or one is created per call
Returns: response based on paramers
Return type: - url (
-
steam.webapi.get(interface, method, version=1, apihost='api.steampowered.com', https=True, caller=None, session=None, params=None)¶ Send GET request to an API endpoint
New in version 0.8.3.
Parameters: Returns: endpoint response
Return type:
-
steam.webapi.post(interface, method, version=1, apihost='api.steampowered.com', https=True, caller=None, session=None, params=None)¶ Send POST request to an API endpoint
New in version 0.8.3.
Parameters: Returns: endpoint response
Return type: