APIs and interacting with the world wide web

Intermediate Importing Data in Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Herein, you’ll learn

  • What APIs are
  • Why APIs are important
  • In the exercises:
    • Connecting to APIs
    • Pulling data from APIs
    • Parsing data from APIs
Intermediate Importing Data in Python

What is an API?

  • Set of protocols and routines
  • Bunch of code
    • Allows two software programs to communicate with each other

ch_2_2.013.png

Intermediate Importing Data in Python

What is an API?

  • Set of protocols and routines
  • Bunch of code
    • Allows two software programs to communicate with each other

ch_2_2.014.png

Intermediate Importing Data in Python

APIs are everywhere

ch_2_2.016.png

Intermediate Importing Data in Python

APIs are everywhere

ch_2_2.017.png

Intermediate Importing Data in Python

APIs are everywhere

ch_2_2.018.png

Intermediate Importing Data in Python

APIs are everywhere

ch_2_2.019.png

Intermediate Importing Data in Python

Connecting to an API in Python

import requests
url = 'http://www.omdbapi.com/?t=hackers'
r = requests.get(url)
json_data = r.json()
for key, value in json_data.items():
    print(key + ':', value)
Intermediate Importing Data in Python

What was that URL?

  • http - making an HTTP request
  • www.omdbapi.com - querying the OMDB API
  • ?t=hackers

    • Query string
    • Return data for a movie with title (t) ‘Hackers’

    'http://www.omdbapi.com/?t=hackers'

Intermediate Importing Data in Python

OMDb API

ch_2_2.033.png

Intermediate Importing Data in Python

OMDb API

ch_2_2.034.png

Intermediate Importing Data in Python

It’s a regular URL!

ch_2_2.036.png

Intermediate Importing Data in Python

Let's practice!

Intermediate Importing Data in Python

Preparing Video For Download...