Today we are going to learn how to use an API with Python. An an API stands for Application Programming Interface–think of it as a way for you to use code to fetch data. We will be using Pro Publica's Nonprofit API and NYC OpenData's API, but the concepts here apply to any API you find online.
- We will be exploring NYC 311 data.
- Create a new account by clicking on
Sign up for an app token!
or through their portal. - Verify your email address.
- Create a new app token.
- Take note of your app token.
- Read the 311 API documentation and Socrata documentation.
-
Navigate to your
data-journalism
folder in terminal. -
Create a new folder for this project and move into that directory.
mkdir my-first-api cd my-first-api mkdir notebooks mkdir output
-
Install libraries we will need for this analysis.
pipenv install jupyterlab pipenv install pandas pipenv install requests
-
Start Jupyter Lab
pipenv run jupyter lab
-
Navigate to
notebooks
and create a Python 3 notebook inside of it.