An Introduction to APIs (Application Programming Interfaces) & 5 APIs a Data Scientist must know!
If you are in tech domain, you will invariably bump in references to something called an “API”. You just can’t skip it – if you do, you are bound to hear it again. APIs are being used almost everywhere. But, if you have ever wondered what exactly is an API? or Why are they important? or How do they help? this article will help you out.
In this article, I will explain what is an API in simple terms. I will tell various categories / types of API. Then I will be introducing you to the different APIs which you commonly encounter in your day to day life. To add more value, I have listed down 5 useful projects you can work on using an API. I bet you will be tempted to try your hands on at least one of them.
Let’s get started!
Table of Contents
- Categories of API
- Difference between an API and a Library
- Walk through an example
- 5 APIs every Data Scientists should know
- List of 5 cool data science projects using APIs
- Welcome to the new playground
In simple words, an API is a (hypothetical) contract between 2 softwares saying if the user software provides input in a pre-defined format, the later with extend its functionality and provide the outcome to the user software. Think of it like this, Graphical user interface (GUI) or command line interface (CLI) allows humans to Interact with code, where as an Application programmable interface (API) allows one piece of code to interact with other code.
One of the most common use case for APIs is on the web. If you have spent a few hours on internet, you have certainly used APIs. Sharing things on social media, making payments over the web, displaying list of tweets through a social handle – all of these services use API at the back.
APIs are widely used by developers for implementing various features in their software. They simply use a simple API call within their software to implement complex features instead of having to code it by themselves.
Let’s try and understand it better with the help of an example:
Pokemon Go has been one of the most popular smartphone games. But in order to build such a game taking in account the large ecosystem, one requires complete information of routes and roads across the globe. I’m sure the developers of the Pokemon Go must have faced a dilemma if they should code the maps of the entire world or use the existing Google maps to build their application on top of it. They choose the latter, simply because it’s practically not possible to create something similar to Google maps in a short span of time.
This is just one example. There are a lot of developers using various APIs to implement complex features into their applications instead of coding it themselves. Therefore, API provides a very convenient way of making code reusable.
Basic elements of an API:
An API has three primary elements:
- Access: is the user or who is allowed to ask for data or services?
- Request: is the actual data or service being asked for (e.g., if I give you current location from my game (Pokemon Go), tell me the map around that place). A Request has two main parts:
- Methods: i.e. the questions you can ask, assuming you have access (it also defines the type of responses available).
- Parameters: additional details you can include in the question or response.
- Response: the data or service as a result of your request.
2. Categories of API
A web API is an interface to either a web server or a web browser. These APIs are used extensively for the development of web applications. These APIs work at either the server end or the client end. Companies like Google, Amazon, eBay all provide web-based API.
Some popular examples of web based API are Twitter REST API, Facebook Graph API, Amazon S3 REST API, etc.
There are multiple OS based API that offers the functionality of various OS features that can be incorporated in creating windows or mac applications.
Some of the examples of OS based API are Cocoa, Carbon, WinAPI, etc.
Interaction with most of the database is done using the API calls to the database. These APIs are defined in a manner to pass out the requested data in a predefined format that is understandable by the requesting client.
This makes the process of interaction with databases generalised and thereby enhancing the compatibility of applications with the various database. They are very robust and provide a structured interface to database.
Some popular examples are Drupal 7 Database API, Drupal 8 Database API, Django API.
These APIs allows access to the various hardware components of a system. They are extremely crucial for establishing communication to the hardware. Due to which it makes possible for a range of functions from the collection of sensor data to even display on your screens.
For example, the Google PowerMeter API will allow device manufacturers to build home energy monitoring devices that work with Google PowerMeter.
Some other examples of Hardware APIs are: QUANT Electronic, WareNet CheckWare,OpenVX Hardware Acceleration, CubeSensore, etc.
3. Difference between an API and a Library
At this point, I believe you might be scratching your head and confusing APIs with libraries. Let me simplify it for you, an application programming interface (API) is an interface that defines the way by which an application program may request service from the libraries.
An API is a set of rules with which the interaction between various entities is defined. We are specifically talking about interaction between two software.
Even a library also has an API which denotes the area of the library which is actually accessible to the user from outside.
4. Walk through an example
IBM Watson has made certain data science APIs public for people like us to build amazing projects with only a few lines of code. Here, we’ll be looking at one such amazing API offered by IBM called Personality Insights.
This API takes as input in JSON, HTML or simple text format. The input contains text related to the person whose personality interests you. It can be anything like tweets, daily experiences, applications, opinion, etc of that person.
The output generated by the API is in the standard format of JSON or CSV file that contains the information on various social traits of that person. And the developer only needs to display this generated file to the user instead of coding the whole functionality yourself.
There is also a demo on the IBM website that can be accessed here. You can choose either the tweets or replies of few famous personalities to analyze their personality traits. The text can also be customized based on what input you want to provide and analyze the personality traits of that person.
You can integrate this API in your code as well and build an application on top of this API.
5. 5 APIs every Data Scientists should know
Facebook API provides an interface to a large amount of data generated everyday. The innumerable post, comments and shares in various groups & pages produces massive data. And this massive public data provides a large number of opportunities for analyzing the crowd.
It is also incredibly convenient to use Facebook Graph API with both R and python to extract data. To read more about the Facebook API, click here.
Google Map API
Google Map API is one of the commonly used API. Its applications vary from integration in a cab service application to the popular Pokemon Go.
You can retrieve all the information like location coordinates, distances between locations, routes etc. The fun part is that you can also use this API for creating the distance feature in your datasets as well. Read here to find out its complete implementation.
Just like Facebook Graph API, Twitter data can be accessed using the Twitter API as well. You can access all the data like tweets made by any user, the tweets containing a particular term or even a combination of terms, tweets done on the topic in a particular date range, etc.
Twitter data is a great resource for performing the tasks like opinion mining, sentiment analysis. For detailed usage of twitter API, read here.
IBM Watson API
IBM Watson offers a set of APIs for performing a host of complex tasks such as Tone analyzer, document conversion, personality insights, visual recognition, text to speech, speech to text, etc by using just few lines of code.
This set of APIs differ from the other APIs discussed so far, as they provide service for manipulating and deriving insights from the data. To know indepth details about this API, read here.
Quandl lets you invoke the time series information of a large number of stocks for the specified date range. The setting up of Quandl API is very easy and provides a great resource for projects like Stock price prediction, stock profiling, etc. Click here, to read more details about Quandl API.
6. List of 5 cool data science projects using API
I am sure that you are fascinated after reading about the above APIs, but wondering if you could a create project using these APIs which will be great value add to your CV? Well, here’s the list of ideas you can start with. You can either use these APIs to retrieve data & manipulate it to extract insights from it or pass the data to these APIs & perform complex functions.
Here are the list of the projects for you. I’ll leave the execution of these ideas to you.
- Social Media Sentiment Analysis : By using data from Twitter and Facebook API.
- Opinion Mining : By using data from Twitter and Facebook API.
- Stock Prediction : By using data from Yahoo Stock API and Quandl API.
- Most Popular languages on Github : By using data from Github API.
- Microsoft Face Sentiment Recognition : By using Microsoft face API.
- Using the meetup API to find right meetup groups
- Mining YouTube for social media analysis
- Subject extraction using Google API
- Use Google Maps API to create distance features
7. Welcome to the new Playground
Take a step back – you have just got a glimpse of an entirely new world. Think of all the possibilities it enables – need face recognition on your mobile application – no worries! just invoke Google Face recognition API. Need to translate documents in Japanese to English – why not try Google Translate! The possibilities are limitless!
A few things to keep in mind while you think of building and using APIs:
- APIs are a robust way to integrate applications. You can theoretically do integrations without APIs in some cases, but that often lands you in difficulty. For example, you want to pull 5 latest tweets from a user. You can do this easily through Twitter API and irrespective of changes happening at the front end of Twitter your results would be correct. If you would have done this using web scrapping, you would need to make changes with every change in web site layout. You would need to worry in case Twitter throws an advertisement in between the last 5 tweets and filter it out!
- APIs might come with a limit on usage. This could be in form of daily limits, number of requests in a time frame etc. This is to ensure that the servers of the service providers are under predictable loads. If you need higher access, check if there is a paid access or talk to the service provider.
- While designing your application, think of what is the best way to use an API. For example, you can send a single request to YouTube and get the top videos with some statistics. On the other hand, you can send one request for each video and get more detailed statistics. What do you need for your application – if you can do what is needed in one call – do it with one call!
After going through this article, I believe you would have acquired a better understanding of APIs and how helpful they can be. I have only mentioned some of the popular APIs but the list is endless. If you would like to add to the list of APIs, please share them in the comments below.
I’ll encourage you to pick up any of the suggested projects and work on it. I bet you’ll be shocked by the power and ease with which you’ll be able to perform a complex task that would otherwise have been difficult to implement yourself.
Did you enjoyed reading this article? Do share your views in the comment section below.
Leave a Reply Your email address will not be published. Required fields are marked *