Create an Amazon search web app in under 30 minutes using streamlit and APIs

Learning components of Data Science can be simple and fun. Whether you are learning or teaching concepts, one of the keys is to make it interesting. Not all concepts need to be learned at the same time. Make it simple. Make it fun.
In Data Science, it may not matter if you can unearth new insights or train the best models. An important aspect of Data Science is making the results accessible to your users or business partners. One way to do that is to create simple interactive web apps to present and interact with findings.
Before you jump in and try to learn advanced techniques, try to do something simple. For instance, could you present data in a way that would interest your cat?
Step 1: What interests your cat?
The key is to find a topic of interest. In this case, what topic keeps your cat’s interest? Bitcoin? Probably not. Catnip toys? Now you are on to something.
Step 2: Where is the data? (5 minutes)
The first place that might come to mind is Amazon. That seems like a reasonable first guess.
Ok, how do you get product data from Amazon? You’re not an associate or a seller, so you need to look for external APIs.
One quick Google search brings us to Rainforest API. There is a 30-day free trial (100 calls). Free is good.
Also good, there is an API Playground to assist you in generating the python code that can be used in the web app. Signing up and getting your first snippet of code takes less than five minutes.

- Build a Simple Web App (5 minutes)
I highly recommend streamlit for a quick and simple web app. I’ve used it for several Data Science applications and have been pleased. In the future, if you need to scale, consider dash. But for now, let’s look at streamlit.
The beauty of Streamlit is that you need to install the package, create a simple .py script, and run the app. Boom, you’re running. You can update the code in one window, and the app automatically picks the change up when you hit Re-run. It’s great!
In my case, I created a new environment. After activating the new environment, I did a pip install streamlit. I ran a simple command, and I was up and running with the world’s simplest script seen below. Seriously, it is that easy.


- Cut and Paste my Rainforest API code (1 minute)
My next step was to cut and paste the Rainforest API code into my script and see what I was dealing with. Instead of print(xx), use st.write(xx) in streamlit.

- Iterate until you are happy (15 minutes to 15 years)
Because I prefer to work with dataframes over JSON, I massaged the JSON response to create a nicer dataframe. Here is what that would look like behind the scenes.

I added two buttons to choose between two specific searches. Another option is to use the text input to search. You can easily see how you might apply this framework to Amazon search tools.

Here is the final code you can run – using your own API key, of course.
Next Steps and Conclusion
Making adjustments and creating new web apps is simple. Just a few tweaks to our cat app, and we have a general Amazon product search UI.

Just 5 more minutes of coding got me to display the raw data in an interactive dataframe and save the results to a .csv file. You can easily see how you can start evolving from a fun little app to a useful Data Science tool!

Thanks for reading, and I hope you can have some fun creating your own web apps! Slowly add to your skillset by adding new features (charts, graphs), and before you know it, you’ll be impressing everyone with your viz skills.