import requests
import pandas as pd
= 100
pd.options.display.max_rows = 100 pd.options.display.max_colwidth
31 APIs — Workbook
In this notebook, we will explore how to make simple API requests.
31.1 Open Brewery Database
https://api.openbrewerydb.org
Open Brewery Database API Endpoints:
- List Breweries
- Get Brewery
- Search Breweries
- Autocomplete
31.2 List Breweries
https://api.openbrewerydb.org/breweries
= requests.get(f"https://api.openbrewerydb.org/breweries") response
response.json()
= response.json() json
pd.json_normalize(json)
31.3 List Breweries Paramaters
- by_city
- by_name
- by_state
- by_postal
- by_type
- page
- per_page
- sort
31.3.1 By City
https://api.openbrewerydb.org/breweries?by_city=Ithaca
= 'Ithaca' city
= requests.get(f"https://api.openbrewerydb.org/breweries?by_city={city}")
response = response.json() json
pd.json_normalize(json)
31.4 By Type
https://api.openbrewerydb.org/breweries?by_city=Ithaca&by_type=micro
= 'Ithaca'
city = 'micro' brew_type
= requests.get(f"https://api.openbrewerydb.org/breweries?by_city={city}&by_type={brew_type}")
response = response.json() json
pd.json_normalize(json)
31.5 Search Breweries
https://api.openbrewerydb.org/breweries/search?query=dog
= 'four' query
= requests.get(f"https://api.openbrewerydb.org/breweries/search?query={query}")
response = response.json() json
pd.json_normalize(json)
31.5.1 Your Turn!
Search for your own keyword by changing the query
variable above! Or create your own API request entirely.
Discuss: What kind of projects or research questions do you think you (or someone else) could do with data from the Open Brewery Database API?
31.6 Open Library API
https://openlibrary.org/developers/api
Open Library API Endpoints - Books - Covers - Lists - Read - Recent Changes - Search - Search inside - Subjects
31.7 Search
http://openlibrary.org/search.json
- Query
- Author
- Title
31.7.2 Your Turn!
Search for your own author by changing the author
variable above!
Discuss: What do you notice about the data returned? What’s confusing or surprising? How might this data be useful?
31.7.3 Books
https://openlibrary.org/works/OL3243784W.json
= requests.get("https://openlibrary.org/works/OL3243784W.json")
response = response.json() json
json
31.7.4 Covers
http://covers.openlibrary.org/b/id/{value}-{size}.jpg
https://covers.openlibrary.org/b/id/6374495-M.jpg
If there is anything wrong, please open an issue on GitHub or email f.pianzola@rug.nl