Minimal Python Flask App, #minimal_python_flask_app - MareMakom
Minimal Python Flask App


The following code will run a minimal Python Flask app. You may use it as a boilerplate for your project.

A minimal Flask application can be created in Python with just a few lines of code. As a lightweight WSGI micro web framework, Flask provides route decorators such as @app.route() to map URL endpoints directly to Python handler functions without requiring extensive boilerplate or scaffolding.

By default, Flask includes a built-in development server capable of running locally with hot reloading and interactive debugging. Below are standard commands and boilerplate code required to configure a virtual environment, install Flask via pip, and launch the development server.


See also: Minimal NodeJS App

Back to Home

First, create and activate a virtual environment (recommended best practice):

python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate

Install Flask using pip:

pip install flask

Save the following code to a file named app.py:

from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello, World!' if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True)

Then run it from your command line:

python app.py

Your minimal Flask web server is now running! Open your browser and navigate to http://127.0.0.1:5000/:

# Output: * Running on http://127.0.0.1:5000/

Main Site for Minimal Python Flask App


External websites and official resources for Minimal Python Flask App:


For additional information, you may search for the term "Minimal Python Flask App" in external resources:


Entry Rating:   3.9 out of 5 (total 3 votes)
Your rating:

Comments and suggestions:

1. For production environments, avoid running the built-in development server (app.run) and instead serve the application behind a production WSGI server like Gunicorn or Waitress.

2. In Flask 2.0 and later, view functions can return Python dictionaries or lists directly, and Flask automatically serializes them to JSON with the application/json header.

3. When using environment variables, you can install python-dotenv and run the application via 'flask run', which automatically detects the FLASK_APP and FLASK_DEBUG settings.

Send a comment (will be published after review):


Additional information:
Search for another phrase
What others contributed:
Recently edited entries