Template Development Kit¶
Use Template Development Kit (TDK) 5.0.0 for DSW 5.0 and document context 19.0. It can maintain template metadata, fetch server content, generate test contexts, package templates and render locally with the same dsw-templating engine as the document worker.
Installation¶
Use Python 3.12 or later (below Python 4), or the compatible TDK container, and keep its rendering dependencies aligned with the instance’s worker.
pip install dsw-tdk==5.0.0
pip install 'dsw-tdk[all]==5.0.0'
The all extra adds the optional dependencies of the weasyprint, excel and rdflib-convert steps, the requests template global and the pandoc-docx-pagebreakpy filter. WeasyPrint also needs Pango, and the pandoc step needs Pandoc installed on the system.
If you do not have Python locally, use the datastewardshipwizard/dsw-tdk Docker image instead. Mount your template project into the container to work with it:
docker run --rm datastewardshipwizard/dsw-tdk:5.0.0 --help
docker run --rm -v "$PWD:/home/user/my-template" datastewardshipwizard/dsw-tdk:5.0.0 verify my-template
Configuration¶
Set DSW_API_URL to the API base of your instance, normally https://<instance>/api, which you can find in the About dialog, and DSW_API_KEY to a permitted API key.
A local untracked .env or the shared ~/.dsw-tdk configuration can provide these values. Do not commit credentials.
dsw-tdk config initcreates the shared configuration with one or more named environments, andconfig editopens it.dsw-tdk -e NAMEselects a named environment for a command, for exampledsw-tdk -e production list.dsw-tdk config dot-envcreates a.envfile for a template project.dsw-tdk config checkshows the configuration that can be loaded.--dot-env,--no-dot-envand--no-configchange which sources are loaded.
Run dsw-tdk --help and a command’s --help for all options.
Template workflow¶
newstarts a local template project using an interactive wizard.listlists available templates;--released-onlyand--drafts-onlynarrow the list.getdownloads a released template or a draft by its<id>:<version>reference.verifyvalidates local template metadata.putuploads the template as a draft;--watchkeeps uploading local changes.packagecreates an importable ZIP (template.zipby default);unpackageextracts one.potextracts translatable messages (totemplate.potby default).
verify, put, package and pot use the current directory unless you specify a template directory. new and get create a new directory named after the template unless you specify one.
dsw-tdk get dsw.questionnaire-report:2.17.0 my-template
dsw-tdk verify my-template
dsw-tdk put my-template --watch
put compares the template’s metamodelVersion with the server. It warns about an older compatible minor version and refuses any other mismatch.
Get a real context¶
dsw-tdk get-context --project PROJECT_UUID --output context.json
dsw-tdk get-context --km-editor EDITOR_UUID --output editor-context.json
dsw-tdk validate-context context.json editor-context.json
Use exactly one source per get-context command. --event can select a project event when used with --project. The file is saved as the server sent it. The command fails when the server’s context metamodel differs from the TDK’s, so use the TDK version matching the server.
validate-context checks files against the 19.0 schema and their own knowledge model, including reply paths and values, files, labels, phase, version and hash. It exits with code 1 on any error. --fix-hash rewrites a hash that does not match the content.
Generate test contexts¶
dsw-tdk generate-context --sample --profile minimal --profile edge --output contexts
dsw-tdk generate-context --km-bundle model.km --profile typical --count 3 --seed 42 --output contexts
dsw-tdk validate-context contexts/*.json
Use exactly one input: --sample (the knowledge model shipped with the TDK), --km-bundle (a .km or .km.gz file), --km-package (a package on the server) or --from (an existing context).
--profileis one ofempty,minimal,typical,fullandedge, and can be repeated.--countsets the variants per profile.--seedand--nowmake the output reproducible.--sourcechooses aprojectorkm-editorcontext.-D KEY=VALUEsets aconfigvalue:clientUrl,appTitle,primaryColororlogoUrl.
With --from, --mutate perturbs the context at the rate of each profile and --anonymize replaces personal data and free text with deterministic placeholders. Use --anonymize before sharing a test context taken from real data, and review the result.
Test with real project answers as well as generated contexts, and inspect the resulting documents.
Render and compare¶
dsw-tdk render --context context.json --format "HTML Document" --output document.html
dsw-tdk render --context contexts --all-formats --output output
--format accepts a format’s UUID or name and can be omitted if the template has only one. Both --context and --format can be repeated, and --context also accepts a directory of *.json files.
A batch renders the context/format combinations and writes summary.json with the status, duration, output and error of each one. The exit code is 1 if any combination fails. Use the result to identify failures and inspect representative outputs for each output format.
The context must be a complete 19.0 context; otherwise, render reports the file, JSON path and problem. A hash that does not match the content only produces a warning. render fills document as the worker does and always uses the template and format being rendered.
Option |
Use |
|---|---|
|
Render with a PO file and set the document language. |
|
Directory with project files, named by UUID or file name. |
|
Set the matching |
|
Save the rendered context; the file passes |
|
Override a value the worker adds to |
|
Provide the |
|
Directories with additional Pandoc filters and templates. |
For field changes, see Document Template Metamodel Versions. Local/server parity also depends on the deployed conversion tools, fonts and custom rendering extensions.
Upgrading from TDK 4.x¶
DSW_API_URLis the address of the instance followed by/api, not the address of the client.Commands take
<id>:<version>references, for exampledsw.questionnaire-report:2.17.0instead ofdsw:questionnaire-report:2.17.0.A pre-5.0
template.jsonis still read and is written back with the singleid. UpdatemetamodelVersionyourself after porting the template code, see Document Template Metamodel Versions.newno longer asks for an organization ID, andputno longer reads it from the instance.In
list --output-format,{template.id}is the ID alone. Use{template.coordinates}for the<id>:<version>reference.renderrequires a complete 19.0 context, so regenerate saved contexts usingget-contextorgenerate-context.--languagenow setsdocument.language.renderno longer providesextras.questionnaire, and the-D defaultAppTitleShortand-D defaultIllustrationsColoroptions are removed.