uv icon indicating copy to clipboard operation
uv copied to clipboard

Is it possible to `uv init` a project starting from a template TOML?

Open NicholasPini opened this issue 1 year ago • 2 comments

I am in the process of creating a bunch of projects that all require the same index settings and constraint-dependencies. I was wondering it is possible to create a project with uv init and pass some kind of option to use a file as a template. I tried --config-file passing a uv.toml with the following content:

[[index]]
name = "some_index"
url = "some_url"
explicit = true

[sources]
some_dep = { index = "some_index" }

# see https://github.com/astral-sh/uv/issues/7703
constraint-dependencies = ["kaleido!=0.2.1.post1"]

but it did nothing. Note that using a workspace is not an option for me.

NicholasPini avatar Nov 25 '24 14:11 NicholasPini

This isn't possible yet. Why isn't a workspace an option?

zanieb avatar Nov 25 '24 22:11 zanieb

I see. I'm not using a workspace because I need all projects to be independent from each other and with their own venv folder.

ultrapoci avatar Nov 26 '24 07:11 ultrapoci

Just some input on this for design purposes. Somewhat different use-case I suppose, happy to move if there's a better spot for it:

I find myself lately creating a lot of small projects; probably has something to do with AI tools like Cursor allowing creating a project to explore something instead of just using a free-standing script. Even though they're small I want uv (already indispensable) and Git, etc., since these "side projects" have a habit of growing beyond initial expectations.

When I create a new project, I find myself always copying ruff, pyright, and pytest settings into pyproject.toml from a prior project since I use mostly the same settings on most all my projects; line length, strict mode, which lints to use/exclude, etc.

So:

As a developer frequently using uv to create a new project I would like to configure pyproject.toml settings to be added to each new project during uv init Such that hand-customization of a new project with routine details is minimized

I'm sure there are other settings that would be worthwhile to "templatize", but this is the aspect that I see drawing my attention most frequently in recent experience.

scanny avatar Mar 24 '25 21:03 scanny

Yeah, this would be really useful. uv is great for managing many small projects, even when not using workspaces. Having some kind of pytemplate.toml in a parent directory and/or in the home config folder, which automatically gets picked up by uv init and adds the configuration from pytemplate.toml, can be useful.

NicholasPini avatar Mar 25 '25 09:03 NicholasPini

Maybe not the ideal solution, but I have been using a cookiecutter template to have this functionality: https://github.com/tim-hilde/dotfiles/tree/main/cookiecutter/python_minimal

tim-hilde avatar Apr 22 '25 08:04 tim-hilde

Bump. Just started using uv, immediately looked for this feature; sad it doesn't exist

xmercerweiss avatar Jun 09 '25 21:06 xmercerweiss

I second this

AndreaRiboni avatar Aug 01 '25 13:08 AndreaRiboni