Prompt Template Framework — 4-layer Jinja2 template engine for LLM applications
Project description
promptfw — Prompt Template Framework
4-layer Jinja2 template engine for LLM applications.
Installation
pip install promptfw
# With token counting:
pip install promptfw[tiktoken]
Quick Start
from promptfw import PromptStack, PromptTemplate, TemplateLayer
stack = PromptStack()
stack.register(PromptTemplate(
id="story.task.write",
layer=TemplateLayer.TASK,
template="Write a {{ genre }} story about {{ topic }} in {{ words }} words.",
variables=["genre", "topic", "words"],
))
rendered = stack.render("story.task.write", {
"genre": "fantasy",
"topic": "a dragon who learns to code",
"words": 500,
})
# rendered.system → system prompt (SYSTEM + FORMAT layers)
# rendered.user → user prompt (CONTEXT + TASK layers)
4-Layer Stack
SYSTEM → Role & base behaviour (stable, cacheable)
FORMAT → Format-specific rules (stable, cacheable)
CONTEXT → Runtime context (dynamic: characters, world, prior text)
TASK → Concrete task (dynamic: what to write now)
rendered = stack.render_stack(
["system.base", "format.roman", "context.scene", "task.write_scene"],
context={
"role": "professional author",
"style_rules": "Show don't tell",
"characters": "Alice, Bob",
"current_scene": "The forest at night",
"task": "Write scene 3.2",
}
)
Load Templates from YAML
# templates/story/task/write_scene.yaml
# id: story.task.write_scene
# layer: task
# template: |
# Write scene {{ scene_id }}: {{ scene_description }}
# Characters: {{ characters }}
stack = PromptStack.from_directory("templates/")
rendered = stack.render("story.task.write_scene", context)
Wildcard Lookup
# Matches "roman.first_draft.scene_generation"
template = stack.registry.get("roman.*.scene_generation")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
promptfw-0.2.0.tar.gz
(8.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file promptfw-0.2.0.tar.gz.
File metadata
- Download URL: promptfw-0.2.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1e76b4b4478e64da1ebef49f387efc5c10cab3c55539b474db7ea0298bcc309
|
|
| MD5 |
1d9c50d2c8ecf268a6067fda25115384
|
|
| BLAKE2b-256 |
9252a84b2bfd5d690f51f25e3dc279c737b924ef5a819f818b41756411c7a584
|
File details
Details for the file promptfw-0.2.0-py3-none-any.whl.
File metadata
- Download URL: promptfw-0.2.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
108b5eeaa599b337071c879737d0f5eaffe5026c3574248260a80711a073834f
|
|
| MD5 |
723143329b49900ec267ac311784d2b6
|
|
| BLAKE2b-256 |
d00b5c032ce0ea15f6acb0122ce4d13150331423fc635f9ea7fb8653d3d3a9de
|