18APIs in Python
In this chapter, we will cover how to deal with APIs (application programming interfaces) using Python. To do this we are going to cover both how to create and access an API and build examples to do both. Before we get to writing any code we need to cover what an API is and why its useful. An API is a mechanism that allows communication between software applications and in this case will cover communication between an application and a web user. The uses of APIs have become increasingly popular allowing users to access data or communicate with services. They give a unified approach to doing so and therefore have become an important aspect to become familiar with, understanding how to communicate with.
We begin by creating our own API to do this. We are going to use the Python packages flask as well as the package flask‐restful. To see if you have the packages you can try and import them.
Now, flask comes by default with the Anaconda distribution of Python but you may not have flask_restful, if that is the case you will need to install it. To do so go to https://anaconda.org/conda-forge/flask-restful to find something like the one shown in Figure 18.1.
Now, while this book has intended to be self‐contained and not rely on many things outside the Anaconda distribution of Python, the url around things like the Anaconda website and subsequent links within it may ...
Get The Python Book now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.