This tutorial will guide you through the process of querying the waste produced in Switzerland in 2021 using the Plasteax API. We will cover how to structure the request and extract relevant data following two approaches:
Command Line (curl command)
Python (requests module)
To retrieve waste data for Switzerland, you need to send a GET request with the appropriate query parameters.
The provided URL is a testing API accessing a database with mock data. To get access to real Plasteax data, use the URL giving access to the real dataset.
The -s flag enables silent mode, hiding progress information. Use piping (|) with the command | jq . to format JSON output for better readability. Using jq is optional, but not doing so results in a less readable output.
You might need to install the jq command in case this is not already present in your system. We refer to for more details regarding the installation of jq.
You may notice that we appended to the API's url the following string:
The string begins with a ? followed by the values of the parameters that one wants to filter through. Each parameter is separated by & , and for values containing a space (like All packaging or All polymers) it is necessary to replace the space character with %20.
The resulting output will provide all the waste metrics related to the queried plastic types, in this case looking like:
Run the following script from a Jupiter note or a Python shell:
import requests
# Define url and desired parameters
url = 'https://2oqef6q7rg.execute-api.eu-west-3.amazonaws.com/plasteax/datasets'
params = {
'country': 'CHE',
'year': '2021',
'polymer': 'All polymers',
'category': 'All packaging'
}
# Get the data from the Plasteax database
response = requests.get(url, params=params)
# Store the output in a JSON format
output = response.json()
# Extract info about waste generated
result = output['elements'][0]['waste_produced_in_the_country']
print(result)
The resulting output provides the volume of waste generated in Switzerland in 2021 across all polymer types and packaging categories: