Skip to main content

Flask-Gen

Flask-Gen is a command-line utility for Flask that simplifies the generation of full Flask projects and modular applications (blueprints). Inspired by Django’s “startproject” and “startapp” commands, it automatically sets everything up by generating a well-structured project with default settings, custom error pages, integration with databases (using Flask-SQLAlchemy and Flask-Migrate), and more.

Features

  • Project Generation: Quickly generate a fresh Flask project with a standard directory structure (e.g., static, templates, and error pages).
  • App (Blueprint) Creation: Rapidly create modular apps (blueprints) that can be directly included in your project.
  • Django-Inspired Workflow: Leverage the convenience of app and project creation as in Django.
  • Preconfigured Setup: Automates the creation of files such as config.py, extensions.py, and default error templates.
  • Extensible: Simple to extend and customize as per your specific requirements.

Installation

Install Flask-Gen using pip (Python version 3.7 and above):

pip install flask-gen

Note: In the unlikely event that the package is not yet available on PyPI, it can be installed from a local clone by running:

pip install .

Usage

Flask-Gen operates in two modes:

1. Execute CLI Commands via flask-gen

These globally available commands enable you to construct a complete project or a modular application (blueprint).

Start a New Project

To begin a complete Flask project with a properly organized setup, use:

flask-gen project <project_name> [path]

Example:

flask-gen project my_flask_project .

This command accomplishes:

  • Checking if a project already exists in the specified location.
  • Setting up the necessary directory structure, e.g., core directories, template directories, static files, and error pages.
  • Generating required files such as config.py, extensions.py, app.py, and a sample .env file.

Create a New Application (Blueprint)

To add a new modular application (blueprint) to an existing project or any directory, use:

flask-gen app <app_name> [path]

Example:

flask-gen app blog .

This command accomplishes:

  • Ensuring an application with the same name does not already exist.
  • Setting up the necessary directory structure, e.g., models/, routes/, and a dedicated templates directory.
  • Generating required boilerplate files, such as a default route and a simple template.

2. Flask CLI Integration for Blueprint Creation

Flask-Gen also provides support for integration with Flask's built-in CLI for generating new blueprints (applications) in an existing project.

Key Points:

  • This is meant for creating new applications, not full-fledged projects.
  • Ensure that you are in the root directory of your Flask application (at the same level as app.py) before running this command.

To build a blueprint with Flask’s CLI integration, run:

flask gen app <app_name> [path]

Example:

flask gen app store 

It leverages Flask’s CLI framework, making it ideal for adding more blueprints in an existing project.

Project Structure

After running the project command, your directory should look like this:

my_flask_project/
├── config.py
├── extensions.py
├── app.py
├── requirements.txt
├── .env.example
└── core/
    ├── __init__.py       # Imports the create_app function from settings
    ├── settings.py       # Default settings with the create_app function
    ├── urls.py           # Placeholder for blueprint registration
    ├── templates/
    │   ├── base.html     # Base HTML template
    │   └── errors/
    │       ├── 404.html
    │       ├── 403.html
    │       └── 500.html
    └── static/
        └── styles.css    # Styles file for customization

When developing a new application (blueprint), the directory layout is as follows:

blog/
├── models/
├── routes/
│   ├── index.py        # Contains a sample route that renders a template
│   └── urls.py         # Registers the blueprint with a URL prefix
└── templates/
    └── blog/
        └── index.html  # Sample template for the blog app

Contributing

Your contributions are welcome. Submit issues or make a pull request in the GitHub repository. See the guidelines in the CONTRIBUTING.md file.

License

This software is released under the MIT License. See the LICENSE file for more information.

Metadata

Release files for Flask-gen 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-gen 0.2.0
File Size Uploaded
flask_gen-0.2.0.tar.gz 9.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-gen 0.2.0
File Interpreter ABI Platform
flask_gen-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.6 kB

Release files / flask_gen-0.2.0.tar.gz

Download URL flask_gen-0.2.0.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5a255bd35deb7bd81d32c6152ebed279fce27df26c420f3a39edeeab1443399b
BLAKE2b-256 checksum
How to use checksums
d10280d293300d691dd147b2c976099438721bdc9fff34a503272946acb63de8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / flask_gen-0.2.0-py3-none-any.whl

Download URL flask_gen-0.2.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
882b9d369f2441e3876557e23a728c39a14511c8cdc8844fa91a53f12fe7f159
BLAKE2b-256 checksum
How to use checksums
ce8e96a4ed286129b7e9b2102b668e4a789dbc254296d1e9692e03d2a1cd44da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page