Shopping Cart

Get Amazing Offers on Scripts

Get UX Support

How to install and create simple API using Flask Python 3.7 in windows 2020?

Previously I have shown you how to install and create hello world application using Python 3.7 in windows 2019?  Please read this article if you are new to python.

Today, I am going to show you how to get into the world of python and also how to create a simple API’s Using one of the best Python Framework Flask. This tutorial is completely made for windows users.

Firstly, Let see what is Flask?

  • Flask is mainly used to create API for web and mobile apps.
  • Flask is a popular Python web framework, meaning it is a third-party Python library used for developing web applications.
  • Flask is a web application framework written in Python.¬†
  • We can use the flask to create frontend (HTML5, CSS, jQuery or Javascript)
  • Armin Ronacher, who leads an international group of Python enthusiasts named Pocco, develops it.
  • ¬†Flask is based on Werkzeug WSGI toolkit and Jinja2 template engine. Both are Pocco projects.

Use cases of Flask?

Flask framework is basically used to create APIs. For example

If you want to create a website and mobile application

Steps that you may follow are as given below.

  • First, you need to choose a backend Technologies and frontend technologies.
  • Let us assume for backend you are going to choose Python and for the frontend you want to choose javascript frameworks like Reactjs, Angular or Mobile applications frontends like Android or swift.
  • For Backend, if we choose python to create an API you must use a third-party library like Flask or Django Rest.

How to Get started with Flask?

First, we need to check whether we installed Python on our System or not?

  • First, go to your desktop and click on the windows icon¬†
  • Then. Type¬†¬†cmd
C:\Users\Your Name>

 

  • Then copy below code¬†Ctrl + C¬†from here and paste by¬†clicking the right mouse button.

 

C:\Users\Your Name>python --version

 

If you find that you do not have python installed on your computer, then you can go through this tutorial how to install and create hello world application using Python 3.7 in windows 2019?.

Getting started with Flask:

Check whether python is installed properly or not. If Python is properly installed then.

C:\Users\Your Name>python --version

 

 

  • Create a project folder¬†where you want to set up your project.

images

 

First, go to Top full path Title bar and Type cmd.

D:\Projects\firstapp>

Installing Flask

pip install virtualenv

mkdir projectname

cd projectname

virtualenv venv

 

To activate the corresponding environment, on windows.

venv\scripts\activate

 

pip install Flask

 

Now.

  • Create a file name¬†app.py
  • Put below code in¬†app.py
from flask import Flask, jsonify

app = Flask(__name__)

tasks = [
    {
        'id': 1,
        'title': u'Buy groceries',
        'description': u'Milk, Cheese, Pizza, Fruit, Tylenol',
        'done': False
    },
    {
        'id': 2,
        'title': u'Learn Python',
        'description': u'Need to find a good Python tutorial on the web',
        'done': False
    }
]

@app.route('/tasks', methods=['GET'])
def get_tasks():
    return jsonify({'tasks': tasks})

if __name__ == '__main__':
    app.run(debug=True)

 

 

To run the code saved in the folder.

D:\Projects\firstapp> python app.py

 

  • Now open your browser and copy the port address from the cmd and paste in your browser

 

Here you run your first API application. In my next tutorial, I am going to show you how to create an app with flask and python.

Leave a Reply

Your email address will not be published.

Free Worldwide shipping

On all orders above $50

Easy 30 days returns

30 days money back guarantee

International Warranty

Offered in the country of usage

100% Secure Checkout

PayPal / MasterCard / Visa