promptpack
The promptpack package is the base library for parsing and working with PromptPack JSON files. It has no framework dependencies and can be used standalone.
Installation
Section titled “Installation”pip install promptpackFeatures
Section titled “Features”- Parse PromptPack JSON files with full validation
- Type-safe Pydantic models for all PromptPack structures
- Template rendering with variable substitution
- Fragment support for reusable prompt components
- Comprehensive error handling
Core Classes
Section titled “Core Classes”PromptPack
Section titled “PromptPack”The main class representing a parsed PromptPack:
from promptpack import PromptPack, parse_promptpack
pack = parse_promptpack("pack.json")
# Access metadataprint(pack.name)print(pack.version)
# Access promptsfor name, prompt in pack.prompts.items(): print(f"{name}: {prompt.system_template}")
# Access toolsfor tool in pack.tools: print(f"{tool.name}: {tool.description}")Prompt
Section titled “Prompt”Represents a single prompt definition:
prompt = pack.prompts["support"]
# Access templatesprint(prompt.system_template)print(prompt.user_template)
# Access variablesfor name, var in prompt.variables.items(): print(f"{name}: {var.type} - {var.description}")
# Render with variablesrendered = prompt.render({"role": "agent", "company": "Acme"})Variable
Section titled “Variable”Represents a template variable:
var = prompt.variables["role"]
print(var.type) # "string"print(var.description) # Variable descriptionprint(var.default) # Default value (if any)print(var.required) # Whether requiredRepresents a tool definition:
tool = pack.tools[0]
print(tool.name) # Tool nameprint(tool.description) # Tool descriptionprint(tool.parameters) # JSON Schema for parametersParsing Functions
Section titled “Parsing Functions”parse_promptpack
Section titled “parse_promptpack”Parse a PromptPack from a file path:
from promptpack import parse_promptpack
# From file pathpack = parse_promptpack("path/to/pack.json")
# From Path objectfrom pathlib import Pathpack = parse_promptpack(Path("path/to/pack.json"))parse_promptpack_from_dict
Section titled “parse_promptpack_from_dict”Parse a PromptPack from a dictionary:
from promptpack import parse_promptpack_from_dict
data = { "version": "1.0", "name": "my-pack", "prompts": {...}, "tools": [...]}
pack = parse_promptpack_from_dict(data)Error Handling
Section titled “Error Handling”The library raises descriptive errors for invalid PromptPacks:
from promptpack import parse_promptpackfrom promptpack.errors import PromptPackError, ValidationError
try: pack = parse_promptpack("invalid.json")except ValidationError as e: print(f"Validation failed: {e}")except PromptPackError as e: print(f"Parse error: {e}")