{"id":13706770,"url":"https://github.com/app-generator/sample-flask-custom-command","last_synced_at":"2025-07-30T19:03:27.640Z","repository":{"id":100503238,"uuid":"355788189","full_name":"app-generator/sample-flask-custom-command","owner":"app-generator","description":"Flask Command-Line - Open-source Sample (Blueprints) | AppSeed","archived":false,"fork":false,"pushed_at":"2021-04-08T15:24:40.000Z","size":3371,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-11T04:43:39.685Z","etag":null,"topics":["appseed-sample","custom-cli","flask-sample"],"latest_commit_sha":null,"homepage":"https://appseed.us/admin-dashboards/flask-dashboard-black","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/app-generator.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-04-08T06:29:39.000Z","updated_at":"2024-03-07T17:07:50.000Z","dependencies_parsed_at":"2023-05-15T11:15:49.049Z","dependency_job_id":null,"html_url":"https://github.com/app-generator/sample-flask-custom-command","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":"app-generator/flask-black-dashboard","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fsample-flask-custom-command","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fsample-flask-custom-command/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fsample-flask-custom-command/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/app-generator%2Fsample-flask-custom-command/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/app-generator","download_url":"https://codeload.github.com/app-generator/sample-flask-custom-command/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222749363,"owners_count":17031913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appseed-sample","custom-cli","flask-sample"],"created_at":"2024-08-02T22:01:07.709Z","updated_at":"2024-11-02T17:07:57.643Z","avatar_url":"https://github.com/app-generator.png","language":"CSS","readme":"# Flask Command Line\r\n\r\n[Flask Command-Line](https://blog.appseed.us/flask-command-line-free-sample/) is an open-source sample project that extends the classic Flask CLI with new commands. The code includes a few commands from a simple `hello` to something more useful like `listing` the application configuration. For newcomers, FLASK CLI gives access to the `application` context, database and helpers.  \r\n\r\n\u003cbr /\u003e\r\n\r\n\u003e Features\r\n\r\n- Define a new Blueprint `commands`\r\n- Define Custom Command `hello` that echos a simple `Hello World`\r\n    - Usage: `flask commands hello`\r\n- Define Custom Command `cfg` that prints all configuration variables and optionally filter the output.\r\n    - Usage: `flask commands cfg` - print all variables used by the app\r\n    - Usage: `flask commands cfg SQL` - filtered output\r\n- Support via **Github** (issues tracker) and [Discord](https://discord.gg/fZC6hup).\r\n\r\n\u003cbr /\u003e\r\n\r\n\u003e Implementation Summary\r\n\r\n- Create the [commands](./app/commands.py) Blueprint\r\n- Update the `app factory` to include and register the Blueprint\r\n- Code `Hello World` command\r\n- Code `Cfg` command\r\n\r\n\u003cbr /\u003e\r\n\r\n\u003e Links\r\n\r\n- [Flask Dashboard Black](https://appseed.us/admin-dashboards/flask-dashboard-black) - Free Starter with more features:\r\n    - Authentication, Blueprints, Dual Config (dev \u0026 production), Deploy scripts.\r\n- [Flask Dashboard Black - Demo](https://flask-black-dashboard.appseed-srv1.com) - LIVE App deployment\r\n\r\n\u003cbr /\u003e\r\n\r\n![Flask Dashboard - Black Design, dashboard screen.](https://raw.githubusercontent.com/app-generator/flask-command-line/master/media/flask-command-line-screen.png)\r\n\r\n\u003cbr /\u003e\r\n\r\n## How to use it\r\n\r\n```bash\r\n$ # Get the code\r\n$ git clone https://github.com/app-generator/flask-command-line.git\r\n$ cd flask-command-line\r\n$\r\n$ # Virtualenv modules installation (Unix based systems)\r\n$ virtualenv env\r\n$ source env/bin/activate\r\n$\r\n$ # Virtualenv modules installation (Windows based systems)\r\n$ # virtualenv env\r\n$ # .\\env\\Scripts\\activate\r\n$\r\n$ # Install modules - SQLite Database\r\n$ pip3 install -r requirements.txt\r\n$\r\n$ # List available commands \r\n$ flask commands # commands = the name of the Blueprint\r\n$\r\n$ # Call Hello Command\r\n$ flask commands hello # this will print a dummy message\r\n$\r\n$ # Call CFG Command\r\n$ flask commands cfg     # list all variables\r\n$ flask commands cfg sql # filter the output that matches `SQL` \r\n$\r\n$ # Set the FLASK_APP environment variable\r\n$ (Unix/Mac) export FLASK_APP=run.py\r\n$ (Windows) set FLASK_APP=run.py\r\n$ (Powershell) $env:FLASK_APP = \".\\run.py\"\r\n$\r\n$ # Start the application (development mode)\r\n$ # --host=0.0.0.0 - expose the app on all network interfaces (default 127.0.0.1)\r\n$ # --port=5000    - specify the app port (default 5000)  \r\n$ flask run --host=0.0.0.0 --port=5000\r\n$\r\n$ # Access the dashboard in browser: http://127.0.0.1:5000/\r\n```\r\n\r\n\u003e Note: To use the app, please access the registration page and create a new user. After authentication, the app will unlock the private pages.\r\n\r\n\u003cbr /\u003e\r\n\r\n## Sample Output\r\n\r\n\u003e Command `hello` - to customize the message, open the [commands](./app/commands.py) file and update `hello()`\r\n\r\n```bash\r\n$ flask commands hello\r\nCustom command - Hello # \u003c-- the output \r\n```\r\n\r\n\u003cbr /\u003e\r\n\r\n\u003e Command `cfg` - Unfiltered output\r\n\r\n```bash\r\n$ flask commands cfg\r\nCustom command - Cfg(None)\r\n  |- ENV -\u003e production\r\n  |- DEBUG -\u003e False\r\n  |- TESTING -\u003e False\r\n  |- PROPAGATE_EXCEPTIONS -\u003e None\r\n  |- PRESERVE_CONTEXT_ON_EXCEPTION -\u003e None\r\n  |- SECRET_KEY -\u003e S3cr3t_K#Key\r\n  |- PERMANENT_SESSION_LIFETIME -\u003e 31 days, 0:00:00\r\n  |- USE_X_SENDFILE -\u003e False\r\n  |- SERVER_NAME -\u003e None\r\n  |- APPLICATION_ROOT -\u003e /\r\n  |- SESSION_COOKIE_NAME -\u003e session\r\n  |- SESSION_COOKIE_DOMAIN -\u003e None\r\n  |- SESSION_COOKIE_PATH -\u003e None\r\n  |- SESSION_COOKIE_HTTPONLY -\u003e True\r\n  |- SESSION_COOKIE_SECURE -\u003e False\r\n  |- SESSION_COOKIE_SAMESITE -\u003e None\r\n...\r\n(truncated output)\r\n```\r\n\r\n\u003cbr /\u003e\r\n\r\n\u003e Command `cfg` - Filtered output (case insensitive)\r\n\r\n```bash\r\n$ # Filter ouput that matches `database`  \r\n$ flask commands cfg database\r\nCustom command - Cfg(Filter=database)\r\n  |- SQLALCHEMY_DATABASE_URI -\u003e sqlite:///...\\flask-command-line-blueprints\\db.sqlite3\r\n$  \r\n$ # Filter ouput that matches `JSON`\r\n$ flask commands cfg JSON\r\nCustom command - Cfg(Filter=JSON)\r\n  |- JSON_AS_ASCII -\u003e True\r\n  |- JSON_SORT_KEYS -\u003e True\r\n  |- JSONIFY_PRETTYPRINT_REGULAR -\u003e False\r\n  |- JSONIFY_MIMETYPE -\u003e application/json\r\n```\r\n\r\n\u003cbr /\u003e\r\n\r\n## Codebase structure\r\n\r\nThe project is coded using blueprints, app factory pattern, dual configuration profile (development and production) and an intuitive structure presented bellow:\r\n\r\n\u003e Simplified version\r\n\r\n```bash\r\n\u003c PROJECT ROOT \u003e\r\n   |\r\n   |-- app/                      # Implements app logic\r\n   |    |-- base/                # Base Blueprint - handles the authentication\r\n   |    |-- home/                # Home Blueprint - serve UI Kit pages\r\n   |    |\r\n   |   commands.py               # Defines the custom commands                 \u003c-- NEW\r\n   |   __init__.py               # Initialize the app                          \u003c-- UPDATED\r\n   |\r\n   |-- requirements.txt          # Development modules - SQLite storage\r\n   |-- requirements-mysql.txt    # Production modules  - Mysql DMBS\r\n   |-- requirements-pqsql.txt    # Production modules  - PostgreSql DMBS\r\n   |\r\n   |-- .env                      # Inject Configuration via Environment\r\n   |-- config.py                 # Set up the app\r\n   |-- run.py                    # Start the app - WSGI gateway\r\n   |\r\n   |-- ************************************************************************\r\n```\r\n\r\n\u003cbr /\u003e\r\n\r\n\u003e The bootstrap flow\r\n\r\n- `run.py` loads the `.env` file\r\n- Initialize the app using the specified profile: *Debug* or *Production*\r\n  - If env.DEBUG is set to *True* the SQLite storage is used\r\n  - If env.DEBUG is set to *False* the specified DB driver is used (MySql, PostgreSQL)\r\n- Call the app factory method `create_app` defined in app/__init__.py\r\n- Redirect the guest users to Login page\r\n- Unlock the pages served by *home* blueprint for authenticated users\r\n\r\n\u003cbr /\u003e\r\n\r\n---\r\nFlask Command Line - Open-source sample provided by **AppSeed [App Generator](https://appseed.us/app-generator)**.\r\n","funding_links":[],"categories":["CSS"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapp-generator%2Fsample-flask-custom-command","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapp-generator%2Fsample-flask-custom-command","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapp-generator%2Fsample-flask-custom-command/lists"}