An Example Flask Project Structure For Google Cloud App Engine

An Example Flask Project Structure For Google Cloud App Engine

The Python Flask web framework is flexible. Unlike Django, it allows the developer to structure their projects in ways they deem fit. This can both be a curse and a blessing, because this can make moving between projects a bit tedious.

In this article, I suggest a Flask project structure that I find useful for Google Cloud App Engine projects.

Project Structure

Here’s the project structure with explanation below:

└── flask-project
    ├── app
    │   ├──
    │   ├── blueprints
    │   │   └── user
    │   │       ├──
    │   │       ├──
    │   │       ├──
    │   │       ├── templates
    │   │       │   └── user
    │   │       └──
    │   ├── extensions
    │   │   └──
    │   ├── static
    │   │   ├── css
    │   │   ├── fonts
    │   │   ├── images
    │   │   └── js
    │   ├── templates
    │   │   ├── layouts
    │   │   └── macros
    │   └── tests
    ├── app.yaml
    ├── config
    │   └──
    ├── .env
    ├── .gcloudignore
    ├── .gitignore
    ├── index.yaml
    ├── instance
    │   └── settings.py_prod
    ├── requirements
    │   ├── common.txt
    │   ├── development.txt
    │   └── production.txt
    └── requirements.txt

flask-project: This is the project root directory. It will contain the actual Flask app together with the necessary App Engine yaml files. .gitignore, .gcloudignore and .env files will all be here.

app.yaml: App Engine configuration file.

index.yaml: Dastastore index configuration file. Project readme.

requirements.txt: The file listing project package dependencies. This is used by App Engine to install dependencies.

app: The Flask application directory. Holds, static, templates, extensions, tests and blueprints directories.

config: The directory holding the app configurations.

instance: Directory holding production sensitive configs (e.g. encryption keys). Should not be in git the repo.

requirements: Directory holding the files containing list of project packages/dependencies.

common.txt: A list of common packages for both development and production environments.

development.txt: List of development specific packages. This file imports common.txt using -r common.txt.

production.txt: List of production specific packages. This file imports common.txt using -r common.txt. The top-level requirements.txt imports this using -r requirements/production.txt.

settings.py_prod: Production sensitive config. Uses a non-python extension so that Flask does not read/find it during development. Appication configs go here. Application entry point holding the Flask object.

blueprints: Directory for Flask blueprints. This holds a blueprints with it’s templates,,,

See below for sample code utilising the above project structure.

Code Snippets

The file inside a blueprints directory will contain:

from flask import Blueprint

user = Blueprint('user',__name__,template_folder='templates')

# views go here...

The file inside a blueprints directory will contain:

from app.blueprints.user.views import user

The file inside the settings directory will contain:

from flask_login import LoginManager

login_manager = LoginManager()

The file inside the root Flask directory(ie app) will tie them all together:

from flask import Flask
from app.blueprints.user import user

from extensions.extensions import (

app = Flask(__name__,instance_relative_config=True)
app.config.from_pyfile('') # production config


I hope you find the above information useful.

Check out other guides

  1. Common Google Cloud CLI Commands
  2. How To Create Your Own Online Portfolio
  3. How To Make Your Resume Stand Out
  4. How To Create A Simple Website


comments powered by Disqus