api-scaffold-cli is an installable Python command line tool that generates a new Flask API project from the base-api template repository.
It clones the template into a new project directory, removes the cloned .git metadata, renames the template identity to your requested project name, and enables or removes optional template features such as PostgreSQL, Celery, and AWS.
- Python 3.10 or newer.
- Git available on
PATH. - Network access when cloning from GitHub.
- Access to the base API repository. By default this is
https://github.com/ti-mae42/python-flask-base-api.
From this repository:
python -m pip install .For development:
python -m pip install -e .Install directly from a GitHub repository URL:
python -m pip install "git+https://github.com/ti-mae42/api-scaffold-cli.git"For editable development from GitHub:
git clone https://github.com/ti-mae42/api-scaffold-cli.git
cd api-scaffold-cli
python -m pip install -e .Generate a project without database support:
api-scaffold new my-api --database=noneGenerate a project with PostgreSQL support:
api-scaffold new my-api --database=postgresqlGenerate a project with MySQL support:
api-scaffold new my-api --database=mysqlGenerate a project with PostgreSQL and Celery:
api-scaffold new my-api --database=postgresql --with-celeryGenerate a project with PostgreSQL, AWS, and Celery:
api-scaffold new my-api --database=postgresql --with-cloud=aws --with-celeryUse a custom template repository and output directory:
api-scaffold new my-api \
--base-repo-url=/path/to/local/base-api \
--output-dir=./generatedThe generated project path is OUTPUT_DIR/PROJECT_NAME. The command fails if that target directory already exists and is not empty.
PROJECT_NAME: Required. The generated project directory and distribution name. Use letters, numbers, hyphens, or underscores, starting with a letter or number. Hyphens are allowed.--database: Optional. Accepted values arenone,postgresql, andmysql. Defaults tonone.--with-celery: Optional flag. Keeps Celery worker support when present. If omitted, Celery-specific code is removed.--with-cloud: Optional. Currently supportsaws. If omitted, AWS-specific code is removed. Unsupported values are treated as cloud disabled and reported as warnings.--base-repo-url: Optional. Git URL or local git repository path for the template. Defaults to theBASE_REPO_URLvalue in this project’s.env.--output-dir: Optional. Directory where the generated project directory is created. Defaults to the current directory.
--with-aws is still accepted as a deprecated alias for --with-cloud=aws.
The scaffold applies these transformations after cloning:
- Removes the cloned template
.gitdirectory. - Renames template identity strings:
Base APIbecomes a display name derived fromPROJECT_NAME, such asMy API.base_apibecomes a safe Python package name, such asmy. A trailingapisegment is omitted from the package name.base-apibecomes the requested project name, such asmy-api.BASE_APIbecomes an uppercase env/config prefix, such asMY.
- Renames files and directories that include
base_apiorbase-api. - Skips binary files and cache/build/virtualenv directories.
- Uses
TEMPLATE_FEATURES.mdfrom the cloned template as guidance for optional feature cleanup. - Removes or keeps database files, dependencies, migrations, environment variables, and startup setup based on
--database. - For PostgreSQL, keeps the PostgreSQL driver and writes a
postgresql+psycopg2://sampleDATABASE_URL. - For MySQL, keeps the MySQL driver and writes a
mysql+pymysql://sampleDATABASE_URL. - Removes or keeps Celery worker files, dependencies, environment variables, startup setup, and worker docs based on
--with-celery. - Removes or keeps AWS adapter files, dependencies, environment variables, and AWS-only docs/config based on
--with-cloud=aws. - Preserves generic infrastructure folders and Flask bootstrap files such as
initialize.py; only clearly optional feature code is removed. - Prints transformation, database, Celery, and cloud logs, including warnings when a cleanup cannot be performed safely.
After generating a project:
cd my-api
cp .env.sample .env
python -m pip install -e .
pytest
flask --app my.initialize:web_app runIf PostgreSQL or MySQL is enabled, configure DATABASE_URL in .env, then run migrations with Flask-Migrate:
flask --app my.initialize:web_app db upgradeIf Celery is enabled, configure the worker broker variables such as REDIS_URL, then start the worker:
celery -A my.initialize:celery_app worker- Only the
base-apitemplate shape is currently supported. - Cloud support is AWS-only for now.
- Optional feature cleanup depends on
TEMPLATE_FEATURES.mdand optional marker comments in the template. - The tool avoids unsafe edits. If a file cannot be safely removed or edited, it is kept and a warning is printed.
- Dependency cleanup is line-based for
pyproject.tomland requirements files. Complex dependency declarations may require manual review. - The generated project is not automatically committed to git.
- The scaffold does not install generated project dependencies or run generated project tests automatically.
git clone fails:
- Confirm Git is installed and available on
PATH. - Confirm
--base-repo-urlis reachable. - For private repositories, confirm your SSH key or Git credentials work outside the scaffold command.
Target directory already exists:
- The command refuses to write into an existing non-empty target directory.
- Choose a different
PROJECT_NAME, set a different--output-dir, or clear the existing directory yourself.
Invalid project name:
- Use only letters, numbers, hyphens, or underscores.
- Start the name with a letter or number.
Feature files were not removed:
- Check the scaffold log warnings.
- Confirm the cloned template contains
TEMPLATE_FEATURES.md. - Confirm optional feature blocks are marked in the template, for example
BASE_API_OPTIONAL: database,BASE_API_OPTIONAL: celery, orBASE_API_OPTIONAL: aws.
Generated imports fail:
- Check whether an optional feature was disabled while application code still imports that feature.
- Review files listed in scaffold warnings.
- Re-run generation with the feature enabled if the project needs it.
System Python refuses installation:
- Some Linux distributions protect system Python environments.
- Use a virtual environment,
pipx, or an editable install inside a project-specific environment.
Run the CLI test suite:
python -m unittest discover