A lightweight Python package for managing and organizing prompt templates with auto-discovery and variable substitution.
Project description
gs_prompt_manager
A lightweight Python package for managing and organizing prompt templates. Automatically discovers, loads, and groups prompt classes that inherit from PromptBase.
Features
- Auto-discovery: finds and loads prompt classes from specified directories
- Template management: define reusable prompt templates with
{variable}and<<MACRO>>substitution - Prompt groups: bundle related variants (system / chat / pre / post / message) under one named group with auto-detection or an explicit
@prompt_groupdecorator - Validation: built-in checks for prompt pieces, metadata, and required fields
- Extensible: subclass
PromptBaseto customize behavior
Quick Start
Installation
pip install gs-prompt-manager
Define a Prompt
from gs_prompt_manager import PromptBase
class GreetingPrompt(PromptBase):
"""A simple greeting prompt."""
def set_prompt(self):
return "Hello, {name}! Welcome to {place}."
def set_name(self):
self.name = "GreetingPrompt"
prompt = GreetingPrompt()
print(prompt({"name": "Alice", "place": "Wonderland"}))
# Hello, Alice! Welcome to Wonderland.
Discover Prompts from a Directory
from gs_prompt_manager import PromptManager
manager = PromptManager(prompt_paths="./my_prompts")
print(manager.get_prompt_names())
greeting = manager.get_prompt("GreetingPrompt")
result = greeting({"name": "Bob"})
Bundle Variants with Prompt Groups
Variants are auto-detected by class-name suffix (System, Chat, Pre, Post, Message, Prompt) and bundled under a single group:
class AssistantSystem(PromptBase): # joins group "Assistant" with key "system"
def set_prompt(self):
return "You are a helpful assistant specialized in {domain}."
class AssistantChat(PromptBase): # joins group "Assistant" with key "chat"
def set_prompt(self):
return "{user_message}"
manager = PromptManager(prompt_paths="./prompts")
asst = manager.get_prompt_group("Assistant")
system_msg = asst.system({"domain": "programming"})
user_msg = asst.chat({"user_message": "Explain decorators"})
Need an explicit group name or key? Decorate the class:
from gs_prompt_manager import PromptBase, prompt_group
@prompt_group("Assistant")
class FormalGreeting(PromptBase): # key derived from class name -> "formalgreeting"
...
@prompt_group("Assistant", "polite")
class FormalGreeting2(PromptBase): # explicit key -> "polite"
...
Solo prompts (no decorator, no recognized suffix) become their own group with key "default".
Documentation
- User Guide — concepts, configuration, and patterns
- Examples — real-world integrations with OpenAI, Claude, multi-agent systems
- Contributing — how to contribute
- Changelog — version history
Key Concepts
PromptBase
The abstract base class. Subclass it and implement at minimum set_prompt and set_name:
class MyPrompt(PromptBase):
def set_prompt(self):
return "Your template with {variables}"
def set_name(self):
self.name = "MyPrompt"
PromptManager
Discovers and loads PromptBase subclasses from one or more directories:
manager = PromptManager(prompt_paths=["./prompts", "./more_prompts"])
prompt = manager.get_prompt("MyPrompt")
PromptGroup
A named collection of related prompts, queried by key:
group = manager.get_prompt_group("Assistant")
group.system({"domain": "law"}) # attribute access -> renders the system variant
group["chat"]({"user_message": "hi"}) # dict-style access
list(group.get_prompt_names()) # ["system", "chat", ...]
Variable Substitution
Two flavors:
- Prompt pieces —
{variable}, user-provided at call time (or via defaults). - Predefined macros —
<<MACRO>>, generated by the prompt class itself.
def set_prompt(self):
return "User {name} logged in at <<DATETIME>>"
Use Cases
- LLM application development: organize prompts for ChatGPT, Claude, Gemini, etc.
- Multi-variant prompts: keep system / chat / pre / post variants together via groups.
- Prompt engineering: version and tag templates with rich metadata.
- Multi-agent systems: separate prompts per agent and per role.
- Prompt libraries: reusable, discoverable template collections.
Requirements
- Python 3.8+
- regex >= 2022.1.18
Contributing
Contributions are welcome. See CONTRIBUTING.md.
License
Apache License 2.0. See LICENSE.
Author
Guan Huang
Links
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
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 gs_prompt_manager-0.0.7.tar.gz.
File metadata
- Download URL: gs_prompt_manager-0.0.7.tar.gz
- Upload date:
- Size: 43.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
759107ec8ec494ef32536f9df23686a367214d76a0a17bbb762504fa4e11f14a
|
|
| MD5 |
0fb9bb691529531f525c6b9fa6c7ef5d
|
|
| BLAKE2b-256 |
ef8860266a8ae992cb487eab5b7db937c9edc5932141ded61f39b97795bc00fa
|
File details
Details for the file gs_prompt_manager-0.0.7-py3-none-any.whl.
File metadata
- Download URL: gs_prompt_manager-0.0.7-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd1d88572a543fa04aa05ba634e67fdb7f3d441e309ddfe02872ed980872114b
|
|
| MD5 |
cffeebbb856f649b70a4f02ff920f1a2
|
|
| BLAKE2b-256 |
99546a6941bb8b2e78acad3bd392483f96c1dfae50fbaa376e39141ded4cf2df
|