May 02

AECData Python Library Step 2— Get filters and retrieve product data

TL;DR

We go step by step and explain how to start with the filtering and retrieval of data on aecdata (see code below).

Done with authentication, on with data retrivals

In our last article we talked about how to set up the first lines of code in your Python script, with information about where to store your token, and how to authenticate and initialize your project.

If you missed the last tutorial, make sure to include the following code at the beginning of your script or notebook:

In this article, we’ll be going through how to run your first commands to get filters and then apply those filters to the API to retrieve product data.

API Data Integration

Get the field descriptions and the available filters

There’s a lot of data in the 2050 Materials universe (>140,000 products with hundreds of fields each). This means that while using the API to build your application or dashboard, it’s wise to filter the data to what you are looking for.

Retrieve field descriptions

Hint

Retrieving field descriptions programmatically can allow you to show these in your own application without worrying about changes.
If you just want to see the descriptions to understand what exists, our docs may be a better place to look at.

Retrieve filters

Retrieving the available filters is a really nice way to create dynamic filters in your application.

Why filter the data at all…? For example, if you’re building a dashboard to plot insulation material emissions for products in Europe, you’ll want to apply the relevant filters for product_type, material_type and continent . This will avoid having to make unnecessary API calls and then filter the data, which will always be inherently slower and will hinder user performance.

Applying the filters and making your first data call

After getting the filters and their mappings, we can now create a filters dictionary which we can supply to the get_products function to retrieve the data.

For this example, we will be retrieving all ceramic tiles (product_types = Tiles, material_type_family=Ceramic)

To do that, we create the filter fictionary as below:

And then we provide the filters to the get_products function

Running a print() function will let you see the JSON object returned by the API. If you are working in a notebook and plan on doing anything related to visualizations, grouping and statistics, it may make sense to transform the data to a DataFrame .

Transform the data to a table or DataFrame

To do any sort of transformation, we developed the ProductData class.
This class is designed to manage and manipulate the data fetched from the 2050-materials API. It offers functionalities for converting data between different formats, scaling product data based on units and amounts, and generating plots for product contributions (more on that in our next tutorial, check it out here)

Done, for now!

You’re now set up with aecdata and have extracted a table of data (in the form of a DataFrame).

Have a look at our next article, where we will be diving into how to use that data to run analytics, statistics, plot informative graphs and generally use it to expand whatever you are building…

Stay tuned, and happy coding!

Previous AECData Python Library Step 1 — Authenticate and Initialize Your Project
Next AECData Python Library Step 3— Visualizations & Statistical Analysis

Related articles

Green Community Concept
Data & Research May 13

In order to measure biodiversity value and foster a future that is nature positive, Ramboll launches Met­ric

The Americas Biodiversity Metric 1.0 is a free biodiversity quantification tool that assists businesses and organizations in achieving their sustainability objectives, which include no net loss of biodiversity, net gain of biodiversity, and transitioning to a more nature-positive state.

Read more
Visualizing Data - Plotting Graphs and Deriving Statistics
Data & Research May 06

AECData Python Library Step 3— Visualizations & Statistical Analysis

Using the open-source Python package aecdata to do statistical analysis and plot graphs.

Read more
AECData Python Library Image
Data & Research Apr 29

AECData Python Library Step 1 — Authenticate and Initialize Your Project

Easy Authentication and User Initialization with AECData

Read more