Skip to main content

CLI tool for creating template based boilerplate projects

Project description

BoilerGen

BoilerGen creates files from reusable templates and injects necessary code (e.g. imports, registrations) directly into your project — without breaking existing code.

No more manual integration steps. No more forgotten imports. Just working boilerplate.

Setup

  1. Run pip install boilergen
  2. Set up your first templates
  3. Fill in the location of your templates in the config file. (can be found via boilergen config)
  4. Run boilergen create and follow the instructions. → All available commands can be accessed by boilergen --help.

Templates

Templates are pre-defined code snippets that can be reused across multiple projects with the same tech stack.
If you already have a boilerplate repository, you may need to edit some snippets to follow BoilerGen's tagging rules.

Templates are configured in the boilergen/templates directory and can be grouped into multiple subgroups (see examples).

Template.yaml

Each template needs a template.yaml file for its Template Definition. We highly encourage you to take a look at the (Example Template repository). Otherwise, here is a quick breakdown:

id: flask  
label: "Flask Base App"  
requires: [example]  
config:  
  debug: True  
  port: 5000

Fields

id The technical identifier for this template (Must be unique across all Templates)
label The human-readable name of this Template (This will be shown in the Template browser)
requires List of templates this template relies on (dependence management). This will be needed for injections. Use the id field of the template.
config A Map of default values for boilergen configurations

Tagging

Often, multiple code snippets depend on each other and can't simply be copy-pasted and expected to work (e.g., special API routes need to be registered in the main API definition before startup). To simplify this process, BoilerGen uses a tagging system to automatically adjust your code.

# <<boilergen:imports
from flask import Flask  
# boilergen:imports>>

Depending on your language of choice, you may need to edit the comment syntax. BoilerGen will comply with this, but the core syntax remains the same.

Tagging Syntax Explained

  • << indicates an opening tag.
  • >> indicates a closing tag.
  • The comment contains the keyword boilergen, identifying it as a special tag.
  • After boilergen, a colon : and a unique identifier (e.g., imports) must follow.
  • Everything between the tag lines is the tag's content and will be used for code injection.

⚠️ Tag opening and closing definitions may not happen inline. They need their own line with with no additional syntax.

⚠️ You must not use this exact syntax (<<boilergen:...>>) in any context not intended for BoilerGen. Doing so will corrupt your template.

⚠️ Identifiers must be unique within a template. We strongly recommend aslo keeping them unique across all templates to avoid confusion.

Example of unique identifiers:

boilergen:main-template_imports
boilergen:main-template_routes

Configurations

To simplify simple variations between projects (e.g., changing the app name or enabling debug mode), templates support configurable variables. These can be set in a template.yaml file or supplied interactively during boilergen create.

debug = bool("boilergen:config | debug | True")

Configuration Syntax Explained

  • Follows the same general structure as tagging.
  • Does not require a unique identifier after the colon.
  • The format is:
    boilergen:config | config_name | default_value
  • The default_value is optional, but must be provided at some point.

Example:

app.run(
    host='boilergen:config | IP | "0.0.0.0"',
    port="boilergen:config | port",
    debug=debug
)

In this example:

  • host will be parsed as a str ("0.0.0.0") .
  • debug is already parsed using bool(...) above

We strongly recommend not placing configuration tags inside inline comments, as this may break the syntax highlighting and parsing in your language-specific editor or runtime. BoilerGen tries to verify data types, but we strongly recommend accepting them as Strings and parsing them individually, depending on your language,


Configuration Precedence

The order of precedence for resolving configuration values is:

stateDiagram-v2
    step1: CLI input during project creation
    step2: Value from template.yaml
    step3: Default value in template
    step1 --> step2
    step2 --> step3

Injections

Injections are a way to specify insertion/editing operations to files of foreign Templates.

Defining Injections

Injection definitions are located inside a special injections; folder at the parent level.

boilergen/
├── templates/
│   ├── base-template/
│   │   ├── template.yaml
│   │   └── template/
│   │       └── api/
│   │           └── test-file.txt
│   └── test-template/
│       ├── injections/
│       │   ├── data-file1.txt
│       │   ├── data-file2.txt
│       │   └── injections.yaml
│       ├── template/
│       └── template.yaml

Generally you define injections in the extending template, not the base template.

injections.yaml

This File lays out a structure on how the injection behaves.

injections:  
  - target: base
    at:  
      file: api/test-file.txt
      tag: start
    method:  
      insert:  
        - bottom  
    from: data-file1.txt
  
  - target: base
    at:  
      file: api/test-file.txt
      tag: main
    method:  
      replace:
    from: data-file2.txt

This setup takes the whole content of data-file1.txt and inserts right before the closing definition of the "start" tag at api/test-file.txt inside the base template. It does the same for data-file2.txt but replaces the whole "main" section of the file.

Fields
name description note possible values
at The relative path to the file to inject into This must be defined inside the requires part of the template.yaml file.
tag The identifier of the tag to inject into Can't be used alongside line in the same injection.
line A single integer describing the line the injection affects Can't be used alongside tag in the same injection.
method what to do with the current tag content insert, replace
-> insert Where to insert the new content Can only be used when method is insert above, below, top, bottom
from The relative path to the file inside the injecting template to pull the content from

Hooks

Hooks are a way to specify operations to be executed on specific times during the project generation process.

Defining Hooks

Hooks are configured in the boilergen/hooks directory. The file name specifies the event the hook is triggered on. Currently supported events are:

  • pre-generation.txt
  • post-generation.txt

Inside those files, you can define shell commands to be executed. Each command is separated by a newline. The execution order is top to bottom.

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

boilergen-1.3.2.post2.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

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

boilergen-1.3.2.post2-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file boilergen-1.3.2.post2.tar.gz.

File metadata

  • Download URL: boilergen-1.3.2.post2.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for boilergen-1.3.2.post2.tar.gz
Algorithm Hash digest
SHA256 452090d2653ae7e6bc02774bdc6ff76ea62ee219a4bf281c0dacf6e49ff47f06
MD5 397577741d424d3e88125d5d401b832a
BLAKE2b-256 e4afd93828e14cac42b9f8d5208850c80008d0201f3be88869eab012d87018c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for boilergen-1.3.2.post2.tar.gz:

Publisher: publish.yml on HumanBot000/BoilerGen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file boilergen-1.3.2.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for boilergen-1.3.2.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 0bb6746583741db0270fa4b06260dc8a88bfb4e59ac6798e98c0f8ecf2a08628
MD5 5a1251242c47f08f9062b46e665194c0
BLAKE2b-256 874c69324bb2c5f133f21885e4fed620e878f6c683176c00e9ae1bdb274f6b81

See more details on using hashes here.

Provenance

The following attestation bundles were made for boilergen-1.3.2.post2-py3-none-any.whl:

Publisher: publish.yml on HumanBot000/BoilerGen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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