0% found this document useful (0 votes)
104 views

Chapter2 PDF

This document provides an introduction to APIs and JSONs. It discusses that APIs are sets of protocols and routines that allow software applications to communicate with each other. JSONs are used for real-time server-to-browser communication and are human readable. The document shows how to load and explore JSON data in Python using the json library. It also discusses that APIs are everywhere and used to interact with the worldwide web. Examples are provided on connecting to an API in Python using the requests library and pulling data from the OMDb API.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views

Chapter2 PDF

This document provides an introduction to APIs and JSONs. It discusses that APIs are sets of protocols and routines that allow software applications to communicate with each other. JSONs are used for real-time server-to-browser communication and are human readable. The document shows how to load and explore JSON data in Python using the json library. It also discusses that APIs are everywhere and used to interact with the worldwide web. Examples are provided on connecting to an API in Python using the requests library and pulling data from the OMDb API.

Uploaded by

vrhdzv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Introduction to APIs

and JSONs
I N T E R M E D I AT E I M P O R T I N G D ATA I N P Y T H O N

Hugo Bowne-Anderson
Data Scientist at DataCamp
APIs
Application Programming Interface

Protocols and routines


Building and interacting with so ware applications

INTERMEDIATE IMPORTING DATA IN PYTHON


APIs
Application Programming Interface

Protocols and routines


Building and interacting with so ware applications

INTERMEDIATE IMPORTING DATA IN PYTHON


JSONs
JavaScript Object Notation

Real-time server-to-browser communication

Douglas Crockford

Human readable

INTERMEDIATE IMPORTING DATA IN PYTHON


JSONs

INTERMEDIATE IMPORTING DATA IN PYTHON


JSONs

INTERMEDIATE IMPORTING DATA IN PYTHON


JSONs

INTERMEDIATE IMPORTING DATA IN PYTHON


Loading JSONs in Python
import json
with open('snakes.json', 'r') as json_file:
json_data = json.load(json_file)

type(json_data)

dict

INTERMEDIATE IMPORTING DATA IN PYTHON


Exploring JSONs in Python
for key, value in json_data.items():
print(key + ':', value)

Title: Snakes on a Plane


Country: Germany, USA, Canada
Response: True
Language: English
Awards: 3 wins & 7 nominations.
Year: 2006
Actors: Samuel L. Jackson, Julianna Margulies
Runtime: 105 min
Genre: Action, Adventure, Crime
imdbID: tt0417148
Director: David R. Ellis
imdbRating: 5.6
Rated: R
Released: 18 Aug 2006

INTERMEDIATE IMPORTING DATA IN PYTHON


Let's practice!
I N T E R M E D I AT E I M P O R T I N G D ATA I N P Y T H O N
APIs and interacting
with the world wide
web
I N T E R M E D I AT E I M P O R T I N G D ATA I N P Y T H O N

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 so ware programs to communicate with each
other

INTERMEDIATE IMPORTING DATA IN PYTHON


What is an API?
Set of protocols and routines

Bunch of code
Allows two so ware programs to communicate with each
other

INTERMEDIATE IMPORTING DATA IN PYTHON


APIs are everywhere

INTERMEDIATE IMPORTING DATA IN PYTHON


APIs are everywhere

INTERMEDIATE IMPORTING DATA IN PYTHON


APIs are everywhere

INTERMEDIATE IMPORTING DATA IN PYTHON


APIs are everywhere

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?
h p - 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

INTERMEDIATE IMPORTING DATA IN PYTHON


OMDb API

INTERMEDIATE IMPORTING DATA IN PYTHON


It’s a regular URL!

INTERMEDIATE IMPORTING DATA IN PYTHON


Let's practice!
I N T E R M E D I AT E I M P O R T I N G D ATA I N P Y T H O N

You might also like