Flask is a Python web application micro-framework built on top of the Werkzeug WSGI library. Flask may be "micro", but it’s ready for production use on a variety of needs.
The "micro" in micro-framework means Flask aims to keep the core simple but extensible. Flask won’t make many decisions for you, such as what database to use, and the decisions that it does make are easy to change. Everything is up to you, so that Flask can be everything you need and nothing you don't.
The community supports a rich ecosystem of extensions to make your application more powerful and even easier to develop. As your project grows you are free to make the design decisions appropriate for your requirements.
Version | Code Name | Release Date |
---|---|---|
0.12 | Punsch | 2016-12-21 |
0.11 | Absinthe | 2016-05-29 |
0.10 | Limoncello | 2013-06-13 |
Use pip to install Flask in a virtualenv.
pip install flask
Step by step instructions for creating a virtualenv for your project:
mkdir project && cd project
python3 -m venv env
# or `virtualenv env` for Python 2
source env/bin/activate
pip install flask
Never use sudo pip install
unless you understand exactly what you're doing. Keep your project in a local virtualenv, do not install to the system Python unless you are using the system package manager.
Create hello.py
:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
Then run it with:
export FLASK_APP=hello.py
flask run
* Running on http://localhost:5000/
Adding the code below will allow running it directly with python hello.py
.
if __name__ == '__main__':
app.run()
If you want to develop and contribute to the Flask project, clone the repository and install the code in development mode.
git clone ssh://github.com/pallets/flask
cd flask
python3 -m venv env
source env/bin/activate
pip install -e .
There are some extra dependencies and tools to be aware of as well.
Used to build the documentation.
pip install sphinx
cd docs
make html
firefox _build/html/index.html
Used to run the test suite.
pip install pytest
py.test tests
Used to run the test suite against multiple Python versions.
pip install tox
tox
Note that tox only uses interpreters that are already installed, so if you don't have Python 3.3 installed on your path, it won't be tested.
If you want to use the latest code, you can install it from the repository. While you potentially get new features and fixes, only numbered releases are officially supported.
pip install https://github.com/pallets/flask/tarball/master