Skip to main content

pftag

ci PyPI Python

A string template processor: %{tags} in text are resolved when the text is used, each optionally piped through functions. Both a library and a command.

Overview

A template is ordinary text with tags in it. A tag is %{, a name, optional functions, }:

run-%{timestamp}-on-%{hostname}.log
%{inputWorkingFile|rmext}.jpg
%{timestamp|replace(:,-)|md5(6)}
%{"Subject12345"|sha256(8)}

Names resolve against the core tags (timestamp, date, hostname, platform, user, pid) and against dictionaries the calling program registers. Functions read left to right, each feeding the next; text after the closing } is kept. Nothing outside %{...} is a tag, so printf "%s", date +%Y%m%d and %20 in a URL pass through untouched. An unknown name is left as written unless --strict.

The full reference is docs/tags.adoc. The pf* family uses pftag wherever a user writes a template on the command line: pfdo_run's --exec string, pflog's telemetry URLs.

Installation

pip install pftag            # no dependencies
pip install 'pftag[names]'   # adds faker, for the dcmname pseudonym function

Python 3.11 or newer.

Command

pftag --tag "run-%{timestamp}-on-%{hostname}.log"
pftag --tag "run-%{timestamp|replace(:,-)|md5(6)}.log"
pftag --tag "run-%{timestamp|strftime(%Y%m%d-%H%M)}.log"
pftag --lookupDictAdd '{"s": {"user": "chris"}}' --tag "user %{user}, hash %{user|md5(8)}"
pftag --tag "%{nope}" --strict        # exit 1: unknown tag
pftag --tag "..." --json              # the whole result: tags found, unknown, legacy, functions applied, errors
pftag --man

Library

import shlex
from pftag import Pftag, TagOptions

tagger = Pftag(TagOptions(lookups={"run": {"subject": "sub-01", "file": "T1.nii.gz"}}))
tagger("%{subject}/%{file|rmext}.jpg").result  # 'sub-01/T1.nii.jpg'
tagger.argv_process(shlex.split("convert %{file} %{file|rmext}.jpg")).argv

process(template) is for text; argv_process(argv) is for commands: split the user's command first, then each argument is a template of its own, so a value with a space or a quote cannot change the shape of the command. lookup_add(name, values) registers a dictionary; a FunctionRegistry passed to Pftag takes new functions with add(name, fn), where fn(value, args) -> str.

Functions

function effect
rmext, ext, basename, dirname path parts
replace(a, b), re(pattern, repl) literal and regular-expression replacement
upper, lower, strip[(chars)], pad(width[, char]), slice(start[, stop]) text shaping
md5[(n)], sha256[(n)] hashing
strftime(format) format a timestamp
mask(pattern) * keeps a character, anything else replaces it
dcmname[(seed)] a LAST^FIRST pseudonym, stable for a seed; needs pftag[names]

Changes in 3.0

  • Tags are %{...} only. The bare %name form is gone; a bare % is always literal. A bare %name of a known name is reported as a 1.x tag (and fails under --strict) so that old templates do not pass through silently.
  • Functions are |fn(arg, arg) in pipe order; arguments bare or quoted; fn or fn(). A quoted head starts a chain from literal text, replacing %literal and echo.
  • Names may contain underscores; %{dict.name} qualifies; two dictionaries defining one name is an error at registration.
  • argv_process for commands. Values are substituted once, never re-processed.
  • Functions renamed to common names: replace, re, mask; ext, basename, dirname, strip, pad, slice, sha256, strftime added; chrplc, strrepl, strmsk, echo gone. dcmname moves behind the names extra and seeds its own generator.
  • Core tags: timestamp, date, hostname, platform, user, pid; os, release, machine, arch, literal gone.
  • No configurable markers, no dependencies, no pudb/loguru/XDG_CONFIG_HOME side effects; pyproject.toml only, CI on 3.11–3.14 and 3.14t, published from a v* tag; the Docker image is no longer built.

Metadata

Release files for pftag 3.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pftag 3.1.0
File Size Uploaded Provenance
pftag-3.1.0.tar.gz 25.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pftag 3.1.0
File Interpreter ABI Platform
pftag-3.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.8 kB

Release files / pftag-3.1.0.tar.gz

Download URL pftag-3.1.0.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5f4817bde16c1c908eea9cfdcaf6704dbf3c607013edbd9437c6de77c4a4db04
BLAKE2b-256 checksum
How to use checksums
9565eeea397945618b87346636f125c01029cab70325e901c8405d0f81a63e90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / pftag-3.1.0-py3-none-any.whl

Download URL pftag-3.1.0-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81a35f6e37f8a3812e7f72f12a54486526e96bbd21dd01a7e7e166c11ea43e6d
BLAKE2b-256 checksum
How to use checksums
6f0e3f6d3d832f998984ee84de9037ff6f9068a0a01802304f67bc1d2646830d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Security for pftag 3.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pftag-3.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page