Python Wrapper For Web API

Farman
3 min readApr 4, 2021

There are many websites providing API (Application Programming Interface) to explore and use website data. Some companies release API wrappers, while others just publish an API and independent developer group will wrap their API in common programming language (e.g. 🐍 Python), which can be used by large community.

Photo by Austin Distel on Unsplash

An organisation creates a public-facing API with the intent that others can use. APIs may be well documented by the company if not, there could be API wrappers created by smart developers for us 🙂. So, a startup or creative developer community can build something better for users, third parties clients (mobile or web apps) with improved UI.

Although, there are many Python API wrappers but in this article, we will see few of them like Tweepy, Wikipedia, Google API Python Client

TWEEPY : Tweepy is a python API wrapper for Twitter API. We can use Tweepy and explore Twitter API easily, which can be helpful in creating third party clients for twitter.

Photo by Ravi Sharma on Unsplash

Example:

  1. Install the Tweepy using pip (pip install tweepy)
  2. Import tweepy and set up your keys and secrets
  3. Create authentication handler and set access tokens
  4. Create Twitter API object and fetch tweets via the user_timeline method

Actually you can do almost all actions for our tweets which we can do in a browser on Twitter. Please check out more on their API doc.

WIKIPEDIA : As we know Wikipedia is an online free-content encyclopedia project helping to create a world in which everyone can freely share in the sum of all knowledge. It is constantly updated and has millions of articles. Wikipedia also has a simple API that’s been wrapped for Python in the wikipedia package.

Photo by Luke Chesser on Unsplash

Example:

  1. Install the wikipedia package using pip (pip install wikipedia)
  2. Import wikipedia and search or view summary of a page.

If we just search for the word “Python” on Wikipedia, it is going to return a list of items containing word “Python”. So we need to be more specific. In next line, we are trying to get summary of the “Python (programming language)” item, and it prints few summary items as well.

Let’s see more info using page method:

Now, we can access and parse data from Wikipedia. And we can do many operations like search Wikipedia, get article summaries, get data like links and images from a page, and more.

This article was only about to highlight Python API wrappers available for many websites and few simple examples . Hope this will encourage us to explore more available Python API wrappers libraries. We can create our own client apps for these popular websites. It would be fun to add some kind of user interface to these client apps.

Please refer below link to have a quick look of Python API wrappers:

https://github.com/realpython/list-of-python-api-wrappers

--

--

Farman

Learner, enthuisast and Android Dev. The best way to learn and stay up to date is simply to do something.