or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdhooks-extensions.mdindex.mdmain-api.mdrepository-handling.mdtemplate-processing.mduser-interaction.mdutilities-exceptions.md
tile.json

tessl/pypi-cookiecutter

A command-line utility that creates projects from project templates, e.g. creating a Python package project from a Python package project template.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/cookiecutter@2.6.x

To install, run

npx @tessl/cli install tessl/pypi-cookiecutter@2.6.0

index.mddocs/

Cookiecutter

A command-line utility that creates projects from project templates (cookiecutters). Cookiecutter enables developers to quickly generate project structures by answering a few questions about their project, making it ideal for scaffolding Python packages, web applications, and other software projects.

Package Information

  • Package Name: cookiecutter
  • Package Type: CLI utility and Python library
  • Language: Python
  • Installation: pip install cookiecutter or pipx install cookiecutter

Core Imports

from cookiecutter.main import cookiecutter

For CLI usage:

from cookiecutter.cli import main

Basic Usage

Command Line Usage

# Create project from GitHub template
cookiecutter gh:audreyfeldroy/cookiecutter-pypackage

# Create project from local template
cookiecutter ./my-template-directory/

# Create project with no user input (use defaults)
cookiecutter template_path --no-input

# Create project with extra context
cookiecutter template_path --no-input key1=value1 key2=value2

Programmatic Usage

from cookiecutter.main import cookiecutter

# Create project from local template
result = cookiecutter('cookiecutter-pypackage/')

# Create project from remote template with extra context
result = cookiecutter(
    'gh:audreyfeldroy/cookiecutter-pypackage',
    extra_context={'project_name': 'my-awesome-project', 'author': 'Jane Doe'},
    no_input=True
)

# Create project with custom output directory
result = cookiecutter(
    'template-path',
    output_dir='/path/to/projects',
    overwrite_if_exists=True
)

Architecture

Cookiecutter's architecture centers around template processing and user interaction:

  • Template Discovery: Locates and validates cookiecutter templates from local directories, Git repositories, or zip files
  • Context Generation: Processes cookiecutter.json files to generate template variables and prompts
  • User Interaction: Prompts users for template variable values with support for various input types
  • Template Rendering: Uses Jinja2 to render template files and directory names with user-provided context
  • Hook System: Executes pre/post generation scripts for custom setup logic
  • Repository Management: Handles cloning, extracting, and caching of remote templates

This design enables maximum flexibility for template creators while providing a consistent, user-friendly interface for project generation.

Capabilities

Main API

Core functionality for generating projects from templates, including the primary cookiecutter() function and CLI interface.

def cookiecutter(
    template,
    checkout=None,
    no_input=False,
    extra_context=None,
    replay=None,
    overwrite_if_exists=False,
    output_dir='.',
    config_file=None,
    default_config=False,
    password=None,
    directory=None,
    skip_if_file_exists=False,
    accept_hooks=True,
    keep_project_on_failure=False
): ...

Main API

Configuration Management

User configuration handling with defaults, file-based config, and runtime overrides for customizing cookiecutter behavior.

def get_user_config(config_file=None, default_config=False): ...
def get_config(config_path): ...
def merge_configs(default, overwrite): ...

Configuration

Template Processing

Context generation, file rendering, and template discovery functionality that powers cookiecutter's core template processing capabilities.

def generate_context(context_file='cookiecutter.json', default_context=None, extra_context=None): ...
def generate_files(repo_dir, context=None, output_dir='.', overwrite_if_exists=False, skip_if_file_exists=False, accept_hooks=True, keep_project_on_failure=False): ...
def find_template(repo_dir, env): ...

Template Processing

Repository Handling

Support for Git repositories, zip files, and URL-based templates with automatic cloning, extraction, and local caching.

def determine_repo_dir(template, abbreviations, clone_to_dir, checkout, no_input, password=None, directory=None): ...
def clone(repo_url, checkout=None, clone_to_dir=".", no_input=False): ...
def unzip(zip_uri, is_url, clone_to_dir=".", no_input=False, password=None): ...

Repository Handling

User Interaction

Interactive prompts for template variables with support for different input types including text, choices, boolean, and JSON inputs.

def prompt_for_config(context, no_input=False): ...
def read_user_variable(var_name, default_value, prompts=None, prefix=""): ...
def read_user_choice(var_name, options, prompts=None, prefix=""): ...

User Interaction

Hooks and Extensions

Pre/post generation hook system and Jinja2 template extensions for enhanced templating capabilities.

def run_hook(hook_name, project_dir, context): ...
def run_pre_prompt_hook(repo_dir): ...
class JsonifyExtension(Extension): ...
class SlugifyExtension(Extension): ...

Hooks and Extensions

Utilities and Exceptions

Helper functions, logging configuration, replay functionality, and comprehensive exception hierarchy.

def rmtree(path): ...
def make_sure_path_exists(path): ...
def configure_logger(stream_level='DEBUG', debug_file=None): ...
class CookiecutterException(Exception): ...

Utilities and Exceptions

Version Information

__version__: str  # Package version string (access via cookiecutter.__version__)

Usage

import cookiecutter
print(cookiecutter.__version__)  # e.g., "2.6.0"