Skip to content

How to Run cookiecutter with uvx for Instant Python Project Templates

Purpose

I wanted to create a new Python project with a proper structure, but I kept avoiding it. Setting up pyproject.toml, CI/CD workflows, documentation scaffolding, and all the boilerplate takes time.

I knew about cookiecutter - a tool that generates projects from templates. But I never installed it. I didn’t want another global package to manage.

Then I discovered I could run cookiecutter with uvx - no installation required.

The Problem with Traditional cookiecutter

To use cookiecutter the traditional way, I would need to install it:

Terminal window
pip install cookiecutter

But this approach has issues:

  1. It pollutes my global Python environment
  2. It may conflict with other packages
  3. I need to remember to update it
  4. It adds another tool to my system that I rarely use

I could use pipx install cookiecutter, but that’s still a permanent installation. I just want to scaffold a project once in a while.

The Solution: uvx cookiecutter

I found that uvx - the tool runner from the uv project - can run cookiecutter without any installation:

Terminal window
uvx cookiecutter https://github.com/fpgmaas/cookiecutter-uv

That’s it. One command.

What happens when I run this:

  1. uvx creates a temporary isolated environment
  2. Downloads and caches cookiecutter
  3. Executes cookiecutter with my template URL
  4. Prompts me for template variables
  5. Generates my project structure

After the command finishes, cookiecutter is gone from my system. But it’s cached, so the next run is fast.

Running the cookiecutter-uv Template

I tried the cookiecutter-uv template, which creates a modern Python project configured for uv:

Terminal window
uvx cookiecutter https://github.com/fpgmaas/cookiecutter-uv

The template prompted me for project details:

Terminal window
project_name [my_project]: my_awesome_lib
project_description [A short description]: A Python library for awesome things
author_name [Your Name]: Jane Doe
python_version [3.12]:

After I answered the prompts, the template created my project structure:

Terminal window
my_awesome_lib/
├── src/
└── my_awesome_lib/
└── __init__.py
├── tests/
└── __init__.py
├── pyproject.toml
├── README.md
├── .pre-commit-config.yaml
└── .github/
└── workflows/
└── ci.yaml

The generated pyproject.toml is already configured for:

  • uv for dependency management
  • Ruff for linting and formatting
  • pytest for testing
  • GitHub Actions for CI/CD

I can start coding immediately:

Terminal window
cd my_awesome_lib
uv sync # Install dependencies

Comparing uvx with pipx and pip

I wanted to understand how uvx compares to other approaches. Here’s what I found:

MethodInstall Required?IsolationSpeedUse Case
uvx cookiecutterNoYes (temporary)Fast (cached)One-off project creation
pipx run cookiecutterNoYes (temporary)SlowerAlternative to uvx
pipx install cookiecutterYesYes (persistent)Fast (installed)Frequent use
pip install cookiecutterYesNo (global)VariesNot recommended

The pipx run command also works without installation:

Terminal window
pipx run cookiecutter https://github.com/fpgmaas/cookiecutter-uv

But uvx is faster. uv caches packages more aggressively and creates environments faster than pipx.

Other Useful cookiecutter Templates

I can use uvx cookiecutter with any template. Here are some popular ones:

PyPI package template:

Terminal window
uvx cookiecutter https://github.com/audreyfeldroy/cookiecutter-pypackage

Data science project template:

Terminal window
uvx cookiecutter https://github.com/drivendata/cookiecutter-data-science

FastAPI full-stack template:

Terminal window
uvx cookiecutter https://github.com/tiangolo/full-stack-fastapi-template

Advanced Usage

I can also use cookiecutter with local templates or specific git branches:

From a local directory:

Terminal window
uvx cookiecutter ./my-template/

From a specific git branch:

Terminal window
uvx cookiecutter https://github.com/user/template --checkout develop

Non-interactive mode with pre-set values:

Terminal window
uvx cookiecutter https://github.com/fpgmaas/cookiecutter-uv \
--no-input \
project_name=my-lib \
author_name="Jane Doe"

The non-interactive mode is useful for automation scripts or CI/CD pipelines.

Why This Matters

I used to avoid project templates because installing cookiecutter felt like too much commitment. Now I can try different templates without cluttering my system.

For team work, I can share a template URL in our documentation. Everyone runs the same command and gets a consistent project structure. No setup required.

The key insight is that uvx removes the friction. When I think “I should use a template for this project,” I just run the command. No planning ahead, no global packages to maintain.

Summary

In this post, I showed how to use uvx cookiecutter to scaffold Python projects without permanent installation. The key point is that uvx handles the temporary environment, letting me run cookiecutter from any template in a single command.

The main benefits I found:

  • Zero installation required
  • Always uses the latest version by default
  • Cached for speed on subsequent runs
  • Clean system with no package conflicts
  • Easy to try different templates

For modern Python projects using uv, I recommend the cookiecutter-uv template. It generates a complete project setup with everything configured for the uv ecosystem.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments