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:
pip install cookiecutterBut this approach has issues:
- It pollutes my global Python environment
- It may conflict with other packages
- I need to remember to update it
- 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:
uvx cookiecutter https://github.com/fpgmaas/cookiecutter-uvThat’s it. One command.
What happens when I run this:
- uvx creates a temporary isolated environment
- Downloads and caches cookiecutter
- Executes cookiecutter with my template URL
- Prompts me for template variables
- 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:
uvx cookiecutter https://github.com/fpgmaas/cookiecutter-uvThe template prompted me for project details:
project_name [my_project]: my_awesome_libproject_description [A short description]: A Python library for awesome thingsauthor_name [Your Name]: Jane Doeauthor_email [[email protected]]: [email protected]python_version [3.12]:After I answered the prompts, the template created my project structure:
my_awesome_lib/├── src/│ └── my_awesome_lib/│ └── __init__.py├── tests/│ └── __init__.py├── pyproject.toml├── README.md├── .pre-commit-config.yaml└── .github/ └── workflows/ └── ci.yamlThe 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:
cd my_awesome_libuv sync # Install dependenciesComparing uvx with pipx and pip
I wanted to understand how uvx compares to other approaches. Here’s what I found:
| Method | Install Required? | Isolation | Speed | Use Case |
|---|---|---|---|---|
uvx cookiecutter | No | Yes (temporary) | Fast (cached) | One-off project creation |
pipx run cookiecutter | No | Yes (temporary) | Slower | Alternative to uvx |
pipx install cookiecutter | Yes | Yes (persistent) | Fast (installed) | Frequent use |
pip install cookiecutter | Yes | No (global) | Varies | Not recommended |
The pipx run command also works without installation:
pipx run cookiecutter https://github.com/fpgmaas/cookiecutter-uvBut 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:
uvx cookiecutter https://github.com/audreyfeldroy/cookiecutter-pypackageData science project template:
uvx cookiecutter https://github.com/drivendata/cookiecutter-data-scienceFastAPI full-stack template:
uvx cookiecutter https://github.com/tiangolo/full-stack-fastapi-templateAdvanced Usage
I can also use cookiecutter with local templates or specific git branches:
From a local directory:
uvx cookiecutter ./my-template/From a specific git branch:
uvx cookiecutter https://github.com/user/template --checkout developNon-interactive mode with pre-set values:
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:
- 👨💻 cookiecutter-uv template
- 👨💻 cookiecutter-pypackage template
- 👨💻 cookiecutter-data-science template
- 👨💻 uv documentation
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments