Skip to content

Create projects from scripts and config files

fastkit init runs without questions when there is no terminal, as in a script or a CI job. It can also save a project's choices to a file and create the same project again from that file.

Without a terminal

Without a terminal, init asks nothing. It needs a project name and refuses to run without one:

$ fastkit init
╭───────────────────────────────── Error ──────────────────────────────────╮
│ ❌ Missing --project-name: there is no terminal to ask for it. Pass      │
│ --project-name NAME or --config FILE.                                    │
╰──────────────────────────────────────────────────────────────────────────╯

Pass --project-name and the options you need; every other choice takes its default. Answers piped to standard input are not read. In a terminal, -y does the same: it keeps the default of every question the options leave open and creates the project without asking.

Save a configuration

--save-config PATH writes the choices of a run to a file. It works with every init run except --dry-run:

$ fastkit init --project-name shop --level domain --database SQLite --feature authentication=JWT --no-venv --save-config shop.toml
...
╭──────────────────── Success ─────────────────────╮
│ ✨ Saved project configuration to 'shop.toml'    │
╰──────────────────────────────────────────────────╯
...
$ cat shop.toml
async_tasks = "None"
authentication = "JWT"
author = ""
author_email = ""
caching = "None"
custom_packages = []
database = "SQLite"
deployment = []
description = ""
level = "domain"
logging = "None"
migrations = "None"
monitoring = "None"
package_manager = "uv"
project_name = "shop"
testing = "Coverage"
tooling = []
utilities = []

The file format follows the extension: .json and .toml always work, .yaml when PyYAML is installed. project_name is the only required key. A file names either a level or a template.

Create a project from a configuration

--config PATH creates the project from the file without asking anything. --project-name, --author, --author-email and --description override the values in the file:

$ fastkit init --config shop.toml --project-name shop2 --no-venv
╭─────────────────────── Info ────────────────────────╮
│ ℹ Loaded project configuration from 'shop.toml'     │
╰─────────────────────────────────────────────────────╯

...
│ Project name    │ shop2                                                      │
...
│ Database        │ SQLite                                                     │
│ Features        │ Authentication: JWT; Testing: Coverage                     │
...

Set the project version

A configuration may set version, a PEP 440 version such as 1.2.0 (quote it in YAML). The generated project then starts at that version instead of 0.1.0. release.toml below is shop.toml with the line version = "1.2.0" added:

$ fastkit init --config release.toml --project-name shop3 --no-venv
...
$ head -4 shop3/pyproject.toml
[project]
name = "shop3"
version = "1.2.0"
description = "[FastAPI-fastkit templated]"

An invalid value is reported (Config key 'version' must be a PEP 440 version such as 1.0.0, got 'one') and nothing is written.

Configurations saved by fastkit 1.x

Files written by fastkit 1.x keep working. A minimal preset (or no preset) creates a fastapi-single-module project, and the CORS and Pagination utilities, which every project now includes, are accepted. For a 1.x file old.json with "architecture_preset": "minimal" and "utilities": ["CORS", "Pagination"]:

$ fastkit init --config old.json --no-venv --dry-run
...
│ Template        │ fastapi-single-module                                      │
│ Database        │ None                                                       │
│ Features        │ Utilities: CORS, Pagination                                │
...

Example: a CI job

The job below is an example, not a file fastkit ships. It creates a project from a committed configuration and runs its tests:

name: generate
on: workflow_dispatch
jobs:
  generate:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v6
      - run: uv tool install fastapi-fastkit
      - run: fastkit init --config shop.toml --no-venv
      - run: cd shop && uv sync && uv run pytest