Skip to main content

Prept

Tool for managing and generating boilerplates.

Prept provides interface for managing a collection of boilerplates and bootstrapping projects by reusing these boilerplates along with the features:

  • Intuitive boilerplate installation and management
  • Flexible template system with support for custom template providers
  • Built-in support for $-substitution and Jinja2 templates
  • Rich Python API for facilitating dynamic generation of boilerplates
  • Extensive customization options to manipulate generation behavior

Installation

Prept can be installed through pip or another Python package manager:

$ python -m pip install prept

Note that Python 3.9 or a higher version is required for installing Prept.

If you intend to use Jinja templates, install through prept[jinja] which installs Jinja2 along with Prept.

Basic Usage

Prept operates on boilerplates which are simply directories containing source code files that can be reused.

Initializing & Installing

To show this, below is an example Python web app template in a directory named web-app-template:

web-app-template
│
├── routers
│   ├── users.py
│   ├── messages.py
│   └── groups.py
│
├── utils.py
└── main.py

We can initialize this directory as a Prept boilerplate by running the prept init command in this directory:

$ prept init python-web-app

python-web-app is the name of boilerplate that will be used to refer to it when generating a project from this boilerplate.

This command creates a boilerplate configuration file preptconfig.json:

web-app-template
│
├── routers
│   ├── users.py
│   ├── messages.py
│   └── groups.py
│
├── preptconfig.json
├── utils.py
└── main.py

We can now globally install boilerplate through prept install command:

$ prept install .

. as argument indicates that boilerplate to be installed is present in the current working directory (same directory as preptconfig.json).

Generating Project

We can now use prept new command supplying this boilerplate's name as argument along with output directory to bootstrap a project from this boilerplate.

$ prept new python-web-app -O my-web-app

my-web-app is the name of output directory where project files are created.

Templating

Prept provides a simple yet flexible templating system that allows generating boilerplate files with values provided by user at generation time.

The following is the content of main.py in the same boilerplate we used in examples above:

import flask

app = flask.Flask(__name__)

@app.route('GET', '/')
def index():
    return {'message': 'Welcome to $APP_NAME'}

if __name__ == '__main__':
    app.run(debug=True)

Here, we are expecting that $APP_NAME can be replaced with a value that user can provide at the time of project generation.

We are using stringsub template provider which provide variable substitutions using the dollar sign ($) syntax as we used in main.py content above.

We define template provider, files, and variables in preptconfig.json. Here is the updated configuration::

{
    "name": "python-web-app",
    "template_provider": "stringsub",
    "template_files": ["main.py"],
    "template_variables": {
        "APP_NAME": {
            "summary": "The name of application.",
            "required": false,
            "default": "Simple Web Application"
        }
    }
}

As we have updated the boilerplate, we must install it again:

prept install .

We can now run prept new command and provide the value for APP_NAME variable for it to be injected into main.py.

$ prept new python-web-app -O my-app
INFO    Generating project from boilerplate: python-web-app
INFO    No existing directory found. Creating project directory at 'D:\Projects\my-app'
INFO    Successfully created project directory at D:\Projects\my-app
INFO    Processing template variables
OPTION  The name of application.

        APP_NAME (optional) [Simple Web Application]: Chat Application

INFO    Creating project files at 'D:\Projects\my-app'

    ├── Creating my-app\main.py ... DONE
    ├── Applying template on my-app\main.py ... DONE
    ├── Creating my-app\routers\groups.py ... DONE
    ├── Creating my-app\routers\messages.py ... DONE
    ├── Creating my-app\routers\users.py ... DONE
    ├── Creating my-app\utils.py ... DONE

SUCCESS Successfully generated project from 'python-web-app' boilerplate at 'D:\Projects\my-app'

The generated main.py in project output directory has the following content:

import flask

app = flask.Flask(__name__)

@app.route('GET', '/')
def index():
    return {'message': 'Welcome to Chat Application'}

if __name__ == '__main__':
    app.run(debug=True)

As you can see, $APP_NAME was replaced with Chat Application.

For complex applications, Prept provides templating based on Jinja. See Templating Guide page in the documentation.

Documentation

Prept comes with an array of useful features and customization capabilities. Listing them all here is not possible.

Read the Prept documentation, specifically the user guide to learn about more features.

Metadata

Release files for prept 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prept 0.2.0
File Size Uploaded
prept-0.2.0.tar.gz 27.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prept 0.2.0
File Interpreter ABI Platform
prept-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.4 kB

Release files / prept-0.2.0.tar.gz

Download URL prept-0.2.0.tar.gz
Size 27.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e5bf38de96a10b06c4a4a8c5304ba00bbe54475d6395d4f986b5a15b02e1d2a5
BLAKE2b-256 checksum
How to use checksums
71013e1c2e05928bbd6e228862532aad0f94d46aeb8e0bb55b0251a493ce4b01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release files / prept-0.2.0-py3-none-any.whl

Download URL prept-0.2.0-py3-none-any.whl
Size 33.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3a46a043cf1f9e313acb7754d8ee07c0afe62a4e96c4acb8ef41ff797f2ead4f
BLAKE2b-256 checksum
How to use checksums
bf539b90d41edd845ef90f744c9c0aa6ce459ebe19eb2fca6a4cdea4becd6565
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page