Skip to main content

A command-line tool to generate Flask projects and applications.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_gen-0.1.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_gen-0.1.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file flask_gen-0.1.0.tar.gz.

File metadata

  • Download URL: flask_gen-0.1.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for flask_gen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 48ee09b7e8fced8f2e56249156b7b61b4bce6066f9e0ce30b0b41e05b690cbd7
MD5 073c4c48a6f0a82005a37e5b94a06f01
BLAKE2b-256 c240a443fbeb0147878a4ec378df972c417fceb70289f4a47522469eb121b7e3

See more details on using hashes here.

File details

Details for the file flask_gen-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flask_gen-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for flask_gen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 446ed039821962be184fcb5faa10ba45c99d37f44c16e584ade92faf633c217b
MD5 d2e3db4b20880a59b74ddcaf5367551c
BLAKE2b-256 66a0f0e399224594d21a48a8fea8b992b373308bba549ab529b0e75c0e29ee84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page