Registry / devops / cookiecutter

cookiecutter

JSON →
library2.7.1pypypi✓ verified 26d ago

Cookiecutter is a command-line utility that creates projects from project templates. It streamlines the setup of new projects, such as Python packages, web applications, or data science projects, by prompting the user for configuration details and rendering files based on Jinja2 templates. Currently at version 2.7.1, it maintains an active release cadence with frequent updates and community contributions, supporting Python 3.10 and newer.

pip install cookiecutter
INSTALL
IMPORT
SIG · COOKIECUTTER
C
cookiecutter
devopspythonv2.7.1
Install
4.2s avg
Import
660ms
Disk
43MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.7.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.678s · 42.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.2s · import 0.642s · 44MB
43MB installed
● package 43MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cookiecutter
from cookiecutter.main import cookiecutter

This example demonstrates how to use `cookiecutter` programmatically. It first creates a minimal local template, then generates a project from it, providing `extra_context` to avoid interactive prompts, and finally cleans up the generated files and template.

from cookiecutter.main import cookiecutter import os import shutil # Define a temporary output directory output_dir = './my_new_project_temp' # Define a simple local template for demonstration template_path = './my_template' # Create a simple template for demonstration purposes # In a real scenario, you'd clone from a Git URL or use a local template. if not os.path.exists(template_path): os.makedirs(os.path.join(template_path, '{{ cookiecutter.repo_name }}')) with open(os.path.join(template_path, 'cookiecutter.json'), 'w') as f: f.write('{"repo_name": "my-project"}') with open(os.path.join(template_path, '{{ cookiecutter.repo_name }}', 'README.md'), 'w') as f: f.write('Hello, {{ cookiecutter.repo_name }}!') print(f"Generating project from template: {template_path}") # Run cookiecutter programmatically # This will prompt for 'repo_name' unless `no_input=True` is used # or default_context is provided. # For a runnable quickstart, we'll provide default_context and no_input. try: cookiecutter( template_path, no_input=True, # Set to False to be prompted extra_context={'repo_name': 'my-generated-project'}, output_dir=output_dir, overwrite_if_exists=True ) print(f"Project successfully generated in {os.path.join(output_dir, 'my-generated-project')}") # Verify a file exists generated_file = os.path.join(output_dir, 'my-generated-project', 'README.md') if os.path.exists(generated_file): with open(generated_file, 'r') as f: print(f"Content of {generated_file}:\n{f.read()}") else: print("Error: Generated file not found.") except Exception as e: print(f"An error occurred: {e}") finally: # Clean up the temporary template and generated project if os.path.exists(template_path): shutil.rmtree(template_path) if os.path.exists(output_dir): shutil.rmtree(output_dir) print("Cleanup complete.")
cookiecutter --version
Debug
Known issues
breakingPython 3.9 and older versions are no longer officially supported. `cookiecutter` now requires Python 3.10 or newer for versions 2.7.0 and later.
fix
Upgrade your Python environment to 3.10 or newer.
affects: 2.7.0+
gotchaIn version 2.7.0, the `cookiecutter -V` command incorrectly reported the version as 2.6.0, despite the installed package being 2.7.0. The programmatic `cookiecutter.__version__` was correct.
fix
Upgrade to 2.7.1 or later, where this issue is resolved.
affects: 2.7.0
gotchaCookiecutter templates can execute arbitrary code through hook scripts (e.g., `pre_gen_project.py`). Users should only use templates from trusted sources, as malicious templates can compromise your system.
fix
Review the template's `hooks` directory before generating a project, and only use templates from reputable sources. Consult the official security policy for details on the trust model.
affects: All versions
gotchaWhen using `jinja2_time` in templates, ensure a timezone is explicitly set (e.g., in `cookiecutter.json` or environment variables) to avoid unexpected date/time behavior, as `jinja2_time` does not provide a default timezone.
fix
Define `_timezone` in your `cookiecutter.json` file or set the `TZ` environment variable before running Cookiecutter.
affects: All versions using jinja2_time
Errors
Common errors & fixes
bash: cookiecutter: command not found
The `cookiecutter` executable is not found in your system's PATH. This usually means `cookiecutter` was not installed correctly or its installation directory is not included in the PATH environment variable.
fix
Ensure `cookiecutter` is installed via `pip install cookiecutter`. If it is, find the Python `Scripts` directory (e.g., `~/.local/bin` on Linux/macOS, or `Python\Scripts` on Windows) where `cookiecutter` is located and add it to your system's PATH environment variable. Alternatively, run it as a Python module: `python -m cookiecutter <template_url>`.
jinja2.exceptions.TemplateNotFound: <template_name>
This error occurs when Jinja2, the templating engine used by Cookiecutter, cannot locate a template file that is being referenced within your Cookiecutter template. This can happen if the path to the template is incorrect, or if files within your Cookiecutter template contain Jinja2 syntax that Cookiecutter attempts to render as a template itself.
fix
Check the paths to templates within your `cookiecutter` template for typos. If the error is for a file that *shouldn't* be rendered as a Jinja2 template, use `_copy_without_render` in `cookiecutter.json` to exclude it, or properly escape Jinja2 syntax within that file using `{{ "{{" }}` and `{{ "}}" }}` to prevent premature rendering.
cookiecutter.exceptions.RepositoryNotFound: A valid repository for "<template_path>" could not be found in the following locations:
Cookiecutter cannot find the specified template repository. This could be due to an incorrect URL, a typo in the path, the repository not existing, or a local path not pointing to a valid Cookiecutter template (i.e., missing `cookiecutter.json` at its root).
fix
Verify the template URL or local path for correctness. Ensure the `cookiecutter.json` file is present in the root of your template directory if you are using a local template. For remote repositories, check your internet connection and the repository's accessibility.
cookiecutter.exceptions.UndefinedVariableInTemplate: 'foo' is undefined
A Jinja2 template within your Cookiecutter template is attempting to use a variable (e.g., 'foo') that has not been defined in the `cookiecutter.json` file or provided as `extra_context` when running `cookiecutter`.
fix
Define the missing variable in your `cookiecutter.json` file, ensuring it has a default value. Alternatively, provide the variable's value using the `--extra-context` command-line argument or `extra_context` parameter if calling `cookiecutter` programmatically.
Upgrade
Version history
2.7.1latest on PyPI · released Mar 4, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
20
Resources
cookiecutter — pip install cookiecutter · libregistry