First and foremost, you'll need a Steam API key. You can get one here.
Create a new environment variable D2_API_KEY
and set its value to the API key. You can then, just use the following code to initialize the wrapper. :
api = d2api.APIWrapper()
Literally just initialize the wrapper inline. That's about it. :
# overrides the environment variable key
api = d2api.APIWrapper('YOUR_API_KEY')
There's a good chance you'd like your responses au naturel. Just set parse_response = False
. The wrapper returns the response text as is (without using the built-in json parser). :
api = d2api.APIWrapper(api_key = 'YOUR_API_KEY', parse_response = False)
Note
While it is highly recommended that a json response have unique key-value pairs, it is not mandatory that they be unique. Some responses of the Steam WebAPI consists of such repeated key-value pairs. Use d2api.src.util.decode_json
to parse these results to avoid losing content.
example1.py
example2.py
example3.py