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/apikeyformat (
str) – response format, either (json,vdf, orxml) only whenraw=Falseraw (class:bool) – return raw response
https (
bool) – usehttpshttp_timeout (
int) – HTTP timeout in secondsauto_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``, ``vdf``, or ``xml``) = '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
requests.Sessionfrommake_requests_session()
- fetch_interfaces()
Returns a dict with the response from
GetSupportedAPIList- Returns:
dictof all interfaces and methods
The returned value can passed to
load_interfaces()
- load_interfaces(interfaces_dict)
Populates the namespace under the instance
- call(method_path, **kwargs)
Make an API call for specific method
- 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 paramssession (
requests.Session) – an instance requests session, or one is created per call
- Returns:
response based on paramers
- Return type:
- 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
Added in version 0.8.3.
- 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
Added in version 0.8.3.