{"id":1300,"library":"cookiecutter","title":"Cookiecutter","description":"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.","status":"active","version":"2.7.1","language":"en","source_language":"en","source_url":"https://github.com/cookiecutter/cookiecutter","tags":["template","project generation","cli","scaffolding"],"install":[{"cmd":"pip install cookiecutter","lang":"bash","label":"Default"}],"dependencies":[],"imports":[{"symbol":"cookiecutter","correct":"from cookiecutter.main import cookiecutter"}],"quickstart":{"code":"from cookiecutter.main import cookiecutter\nimport os\nimport shutil\n\n# Define a temporary output directory\noutput_dir = './my_new_project_temp'\n\n# Define a simple local template for demonstration\ntemplate_path = './my_template'\n\n# Create a simple template for demonstration purposes\n# In a real scenario, you'd clone from a Git URL or use a local template.\nif not os.path.exists(template_path):\n    os.makedirs(os.path.join(template_path, '{{ cookiecutter.repo_name }}'))\n    with open(os.path.join(template_path, 'cookiecutter.json'), 'w') as f:\n        f.write('{\"repo_name\": \"my-project\"}')\n    with open(os.path.join(template_path, '{{ cookiecutter.repo_name }}', 'README.md'), 'w') as f:\n        f.write('Hello, {{ cookiecutter.repo_name }}!')\n\nprint(f\"Generating project from template: {template_path}\")\n# Run cookiecutter programmatically\n# This will prompt for 'repo_name' unless `no_input=True` is used\n# or default_context is provided.\n# For a runnable quickstart, we'll provide default_context and no_input.\n\ntry:\n    cookiecutter(\n        template_path,\n        no_input=True, # Set to False to be prompted\n        extra_context={'repo_name': 'my-generated-project'},\n        output_dir=output_dir,\n        overwrite_if_exists=True\n    )\n    print(f\"Project successfully generated in {os.path.join(output_dir, 'my-generated-project')}\")\n    # Verify a file exists\n    generated_file = os.path.join(output_dir, 'my-generated-project', 'README.md')\n    if os.path.exists(generated_file):\n        with open(generated_file, 'r') as f:\n            print(f\"Content of {generated_file}:\\n{f.read()}\")\n    else:\n        print(\"Error: Generated file not found.\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # Clean up the temporary template and generated project\n    if os.path.exists(template_path):\n        shutil.rmtree(template_path)\n    if os.path.exists(output_dir):\n        shutil.rmtree(output_dir)\n    print(\"Cleanup complete.\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer.","message":"Python 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.","severity":"breaking","affected_versions":"2.7.0+"},{"fix":"Upgrade to 2.7.1 or later, where this issue is resolved.","message":"In 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.","severity":"gotcha","affected_versions":"2.7.0"},{"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.","message":"Cookiecutter 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Define `_timezone` in your `cookiecutter.json` file or set the `TZ` environment variable before running Cookiecutter.","message":"When 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.","severity":"gotcha","affected_versions":"All versions using jinja2_time"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}