Python and APIs – NASA’s Open APIs

I often work with Alta3 Research to provide Python Training solutions for corporate enterprises. The video below is one I made for Alta3 Research documenting the use of Python to interact with NASA’s Open APIs by leveraging the HTTP / HTTPS protocol.

A video I created for Alta3 Research on using Python to interact with APIs

Using Python to interact with APIs using HTTP / HTTPS is a critical skillet for anyone looking to automate solutions within their infrastructure. In this lab, the messaging is rather simple. Of the many HTTP / HTTPS verbs (POST, DELETE, PUT, etc.), we’ll only be utilizing the GET. Consider the model below.


(our code)
Python Client ------- HTTPS GET -------> NASA API
                         <------ 200 + JSON -------

The Python client handles the crafting and sending of the HTTPS GET message to NASA’s APIs. A GET is actually the same message your browser typically sends when requesting HTML data from a web-server.

Our code must also allow processing of the 200 HTTPS response, as well as the attached JSON. Again, a 200 is the same message your browser would expect to receive when interacting with a web-server. However, rather than processing HTML, we’ll be processing JSON.

What is JSON? It’s just a simple way to serialize data. I should do a blog post on it sometime, but for now, check out the IETF’s whitepaper (standard) on The JavaScript Obejct Notation Data Interchange Format (RFC 7159). It is quite a bit like Python lists and dictionaries, so you might also try checking out my post on Python dictionaries.

What is a “NASA Open API”?

In addition to putting people on the moon, and going to Mars, NASA helps the people of the world better understand science. Learning to work with APIs, and the data-sets they can expose, has quickly become core tenant of STEM fields, which is why we find NASA hosting “open APIs”.

The terms “API”, “open”, “rest”, and “restful”, are vague terms. In this case, NASA has created an open data-set that is free to use. Per the NASA API wesbite, “You do not need to authenticate in order to explore the NASA data. However, if you will be intensively using the APIs to, say, support a mobile application, then you should sign up for a NASA developer key

Signing up for a developer key is rather painless, and free. Besides sounding mighty impressive, it will allow you to use the APIs more rapidly without experiencing “rate limiting”.

A short video I made for Alta3 Research on using Python as a client to interact with NASA APIs.

If you get stuck lost, make a comment below and I’ll be sure to follow up with a solution!

Looking for a Python Trainer?

Like what you see? Be sure to click around the rest of my site for more Python training snippets. If you’re still impressed, and happen to be a director or training coordinator looking for an awesome trainer, be sure to reach out. I’ve been training corporations for over a decade. Every course can be customized to best meet the needs of your team.

Previous
Previous

Setting a vim Color Scheme

Next
Next

Python Looping with while and for