Convert your template

With pytemplate-uv 3.8 and later, a Copier or cookiecutter template can become a pack without a rewrite from scratch. This page is for template authors. Read Template packs for the layout a pack needs, and Publish a pack to list the result.

Conversion keeps your template's files and most of its questions. The checks decide what remains to fix: run pack check after each step, and fix what it reports.

Copier

A Copier template is adapted in place. Work in a copy of the template's repository.

  1. Add pytemplate-pack.toml at the root, with contract = 1, an id, name, description, version, and categories (see Publish a pack).

  2. Add a profile.toml for each profile, with name, description, and kind (cli, library, or service). pytemplate schema profile prints the full format. Its lifecycle commands must start with uv, such as uv sync and uv run pytest.

  3. Run the check and fix what it refuses:

    uvx pytemplate-uv@latest pack check . --lifecycle
    

The check refuses these Copier settings, because they run code or read data outside the template:

  • _tasks: remove them. A check the project should run belongs in the lifecycle commands, which must start with uv.
  • _jinja_extensions: remove them, and rewrite the templates that used them with the built-in filters.
  • _migrations: remove them. Packs do not run migrations.
  • _external_data, and any symlink or git submodule: copy the content into the template instead.

Run pack check --lifecycle again until it passes.

cookiecutter

A cookiecutter template is rewritten, and the pytemplate-author skill can do the rewrite with you. The changes are:

  • Each cookiecutter.x variable becomes x, in file names, folder names, and template text. For example, {{ cookiecutter.project_name }} becomes {{ project_name }}.
  • The questions in cookiecutter.json move to questions.yml.
  • Hooks never run: pytemplate does not run hooks/pre_gen_project.py or hooks/post_gen_project.py. Turn what a hook did into a question or a component, or drop it, and delete the hooks/ folder.
  • The layout becomes a pack: a profile folder with its profile.toml and template/, as in Template packs.

Then run pack check --lifecycle as above.

Keep the license and credit

The template's license and copyright lines stay. Keep its LICENSE file, and its copyright notices in the source files. In the pack's README, say "adapted from" the original, with its tag and commit. A pack you adapt must not use the original's name or branding for itself; give the pack its own id and name.

Test the result

Render a project under a new name, and run its tests:

uvx pytemplate-uv@latest create new-name -p PROFILE --template ./my-pack -y
cd new-name && uv sync && uv run pytest

A pack is ready to list when each profile renders, its tests pass in a project made from it, and pack check --lifecycle reports no errors.

Edit this page on GitHub