A Python Web Framework !!
What is Flask ?
Flask is Python Web Framework . Unlike Django it is considered as Micro -Framework as it does not require set of tools or libraries.
Flask is WSGI ( Web Server Gateway Interface) it means that it is a specification that describes how a web server communicates with web applications, and how web applications can be chained together to process one request
Origins Of Flask
Flask was originally designed and developed by Armin Ronacher as an April Fools Joke in 2010. Despite the origin as a joke, the Flask framework became wildly popular as an alternative to Django .
Flask’s success created a lot of additional work in issue tickets and pull requests. Armin eventually created The Pallets Projects collection of open source code libraries after he had been managing Flask under his own GitHub account for several years. The Pallets Project now serves as the community-driven organization that handles Flask and other related Python libraries such as Lektor, Jinja and several others.
Yes , You Read Right Flask is Open Source !!
Flask Vs Django
One Biggest Problems for Machine Learning Engineers ,AI Engineers and Data Scientists is deploy their model . Often deploying model is huge task for Python Developers . Then Enters Flask , Streamlit & Django . Streamlit is for Small applications and Data Visualizations and still upcoming state . SO , Lets take a look at Flask & Django
Django is more complex application while compared to flask . Flask is simple with it’s ability to scale up complex applications .
Flask provides support for API while Django doesn’t have any support for API but Django offers dynamic HTML pages whereas Flask doesnt support
To summarize Flask is WSGI framework while Django is a Full Stack Web Framework.
First Install Pip
$ python -m pip --version
PIP is a package manager for Python packages,A package contains all the files you need for a module.Modules are Python code libraries you can include in your project.Then
pip install -U Flask
Now Let’s Check a Simple Flask App
Where everyone will start . Yes, it is Hello World Program !!
from flask import Flask
app = Flask(__name__)
return 'Hello World'
if __name__ == '__main__':
- First we imported the
- Create app, that hosts the application
- Then you need a route that calls a Python function. A route maps what you type in the browser (the url) to a Python function
- The function should return something to the web browser,
- (app.run()) This is Python for “if this script is run directly then start the application”.
$ env FLASK_APP=hello.py flask run
* Serving Flask app "hello"
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)