Programming API's In Python | PART-2 | extrovert.dev -->

Programming API's In Python | PART-2

Programming API's In Python | PART-2
Friday, February 15, 2019


Finally we reached to Part-2 of our programming API with python , Hope you have enjoyed our last post. If you have entered directly into this post , I suggest you to checkout our previous Post which contains some necessary basics of API. Now let's get our hands dirty with this tutorial.

Our tutorial needs these tools to start.
  • Python 3 🐍
  • Flask
  • requests
To install python 3 use python.org





Now lets pip to install Flask and requests packages.



You can do this within the console itself eliminating flask as requirement. But i am a lazy Author. it helps my other posts that deals with webhooks in Flask. Lets see the usage of requests.

Requests:

Requests is a python library that is used to make requests to a webpage. It simply performs an action just like a browser does with a webpage to display it's content. Dont compare a browser with requests as it is much known for its advanced functions. You can also Urllib (A python library with similar functions ).

Now lets import our packages



Iam using JSON library to manage the output of the request. If you are using console , I suggest you to use pprint (pretty print library).

Now lets write our request to market API which is provided by Indian govt Opensource portal. Now headover to this data.gov.in to get your API_KEY. If you browse the API link in a browser you will see a json printed over your screen. These json consists of all data. There is some useless data too.

To get rid of that useless data we will be iterating over records key which has the required values.



Replace your API_KEY with YOUR_API_KEY variable in the code.

When you finish,your python file it looks like this.



Now save your python file and run

Python filename.py

Now open this http://0.0.0.0:5000/ url in your browser for the result.

0 Response to Programming API's In Python | PART-2

Comments are personally moderated by our team. Promotions are not encouraged.

Post a Comment