Your organization's templates

With pytemplate-uv 3.8 and later, a firm can keep its own templates in a private index and point pytemplate-uv at it. The public hub is then optional. This page is for platform teams. Read Template packs for the pack format and the index file for the search format.

Host an index

An index is the same data the hub publishes, in two forms:

  • For -h: a folder of entries, one file per pack, at OWNER/PACK.toml, as in the hub's index/ folder. PYTEMPLATE_HUB_URL is the base address of that folder, so the entry for acme/pricing-api is read from $PYTEMPLATE_HUB_URL/acme/pricing-api.toml.
  • For search: an index.json in the format described in the index file. PYTEMPLATE_HUB_SEARCH_URL points at it.

Each entry pins a tag to a commit and a digest, so a pack that changes after it was checked is refused, as it is on the public hub. The firm's own checks decide what goes into the index; the hub's checks are not run for a private index.

Point the tools at it

Set both variables for every user, for example in a shell profile or the portal's environment:

export PYTEMPLATE_HUB_URL=https://templates.example.internal/index
export PYTEMPLATE_HUB_SEARCH_URL=https://templates.example.internal/index.json

Then the usual commands read the firm's packs:

uvx pytemplate-uv@latest search api --json
uvx pytemplate-uv@latest create pricing-api -h acme/pricing-api@v2.1.0 -p fastapi -y

Call it from an internal portal

A developer portal can create projects without a shell, through the supported pytemplate.api module. This example renders a pack from a firm's checkout:

from pathlib import Path

from pytemplate import api

request = api.RenderRequest(
    "fastapi",
    "pricing-api",
    Path("/srv/projects"),
    components=("database",),
    no_input=True,
    template="/srv/templates/pricing-pack",
)
plan = api.plan(request)  # writes nothing
print(plan.files)  # every file that would be generated
api.render(request)  # then render the project

template also takes a git source, with template_ref, template_commit, and template_digest to refuse a changed pack, as on the command line. To use a pack from the index, set hub to acme/pricing-api@v2.1.0 instead of template.

Keep the portal's own checks around this call: who may request a project, and where its files go. The generated project runs its own code when someone runs its tests or its build.

Edit this page on GitHub