How to get data from an API using requests

1 min readAPIDataData Gathering
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

In order to get data from an api, you will need to perform an HTTP call against this API.

That is  in simple words a way to make your computer communicate with another service.

To do so, we will need to use the requests Python library.

The API of interest

There exist many APIs, some are free, some other are paid.

If you wonder if a service you know has an api, try googling it with the name API at the end, you might end up finding something.

Today we are using Animechan

Because it is an easy to demonstrate, no authentication required api, which gives you a random anime quote.

Perform an HTTP call

import requests # The library used to make the call

# We define the url
random_quote_url = "https://animechan.vercel.app/api/random"

# We perform the HTTP get call against the api
anime_requests = requests.get(random_quote_url)

# We print out the response
print(anime_requests.json())
Example of getting a random quote from the anime API

Here you are, you can now work with the just you just got back from the api.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.