FANDOM


Requirements Edit

The only requirement is to have the requests Python module installed.

If you don't have the requests module, run this in your command prompt.

pip install requests

Then in your python files, you import both requests and json, like so:

import requests, json


Requesting Edit

After you've imported it, you can then use the .get() method of the requests module to read from the API

fetchedData = requests.get(f"{base_url}/{api_endpoint}/{parameters}")
fetchedData = fetchedData.json() # parse as JSON so you can work on it


Handling the Returned JSON Edit

Parsed JSON in Python is equivalent to a dictionary, so once you've finished fetching the JSON data you can just treat it as you would any other Python dictionary.

To access a specific entry, you'd do

fetchedData['firstlvl']['secondlvl']

I noticed that there are no Python wrappers for P&W, so I started work on one: PW4py . If you know Python, pls help me on this :)

-- JDTech

Community content is available under CC-BY-SA unless otherwise noted.