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, or xml) only when raw=False
  • raw (class:bool) – return raw response
  • https (bool) – use https
  • http_timeout (int) – HTTP timeout in seconds
  • apihost (str) – api hostname, see APIHost
  • 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, or xml)

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.Session from make_requests_session()

fetch_interfaces()

Returns a dict with the response from GetSupportedAPIList

Returns:dict of 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

Parameters:
  • method_path (str) – format Interface.Method (e.g. ISteamWebAPIUtil.GetServerInfo)
  • kwargs – keyword arguments for the specific method
Returns:

response

Return type:

dict, lxml.etree.Element or str

doc()
Returns:Documentation for all interfaces and their methods
Return type:str
class steam.webapi.WebAPIInterface(interface_dict, parent)
doc()
Returns:Documentation for all methods on this interface
Return type:str
class steam.webapi.WebAPIMethod(method_dict, parent)
doc()
Returns:Documentation for this method
Return type:str
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:

dict, lxml.etree.Element, str

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:
  • interface (str) – interface name
  • method (str) – method name
  • version (int) – method version
  • apihost (str) – API hostname
  • https (bool) – whether to use HTTPS
  • params (dict) – parameters for endpoint
Returns:

endpoint response

Return type:

dict, lxml.etree.Element, str

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:
  • interface (str) – interface name
  • method (str) – method name
  • version (int) – method version
  • apihost (str) – API hostname
  • https (bool) – whether to use HTTPS
  • params (dict) – parameters for endpoint
Returns:

endpoint response

Return type:

dict, lxml.etree.Element, str