This is Part 2 of a short 'how to' get weather data. In this tutorial, I'll go over how to get data from NOAA (and also NDAWN for those interested in North Dakota weather).

API stands for Application Programming Interface. Essentially, it is the set of rules programmers must follow to build appication software. For our purposes, we will be using an API to interact with a webserver. The idea behind an API is to allows you, the client, to talk directly to the server. In our case, we will be sending the server a request and the server will then process the request and send back the relevant information. Usually this happens all in the background when you visit a website and click on the links, however, we can write a script to access the data and use it for our own purposes.

One of those purposes might be to request data for an app. Perhaps you are building a weather app and need some up-to-date information. You might request that from NOAA using an API. One of the benefits of using an API is that it can be accessed by almost any programming language, and it tends to run faster than web scraping. In addition, the data is provided (usually) in a JSON format which can be easily formatted to something friendly for analysis (like a csv).

One of the drawbacks is that often websites will require an API key which acts as a password to access the information. The key should also be treated as such and kept to yourself.

NOAA API¶

To access NOAA data, you will first need to get an API key. NOAA has an easy way to do this via an email request and they will send you your key (it's also worth noting that it is free). You will need to include this key in each request you pass to the server.

You can find the online documentation from NOAA here and additional documentation on each dataset (including what the sometimes cryptic codes mean) here.

Let's go through an example to get the weather from a year ago today.