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 - Attribute access:
manager.Assistantreturns the group directly — no boilerplate lookup required - Validation: built-in checks for variables, 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")
# Explicit lookup
asst = manager.get_prompt_group("Assistant")
# Attribute shorthand (equivalent)
asst = manager.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
Full documentation is hosted at gs-prompt-manager.readthedocs.io.
- User Guide — concepts, configuration, and patterns
- Examples — real-world integrations with OpenAI, Claude, multi-agent systems
- Migration Guide — upgrading from earlier versions
- 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")
Attribute-style access is also supported. Groups take priority; falls back to the bare prompt instance if no group matches:
manager.Assistant # → PromptGroup
manager.MyPrompt # → PromptBase instance (if no group named "MyPrompt")
dir(manager) includes all group and prompt names for tab-completion.
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:
- Variables —
{variable}, user-provided at call time (or viaset_variable_defaults). - Macros —
<<MACRO>>, generated by the prompt class itself (viaset_macros).
def set_prompt(self):
return "User {name} logged in at <<DATETIME>>"
def set_variable_defaults(self):
self.variable_defaults = {"name": "guest"}
def set_macros(self):
import datetime
self.macros = {"<<DATETIME>>": datetime.datetime.now().isoformat()}
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.9.tar.gz.
File metadata
- Download URL: gs_prompt_manager-0.0.9.tar.gz
- Upload date:
- Size: 46.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b68cd0c9aa554228242dcf490f306eba38abaf607e0981d0215c8f499716560d
|
|
| MD5 |
c971e0f101b571ac99a389b56a16f530
|
|
| BLAKE2b-256 |
b01ea29f098657132e1e9dda70da9d06e7e9e71746d985da039ef92577010e16
|
Provenance
The following attestation bundles were made for gs_prompt_manager-0.0.9.tar.gz:
Publisher:
publish-to-pypi.yml on CoronRing/gs_prompt_manager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gs_prompt_manager-0.0.9.tar.gz -
Subject digest:
b68cd0c9aa554228242dcf490f306eba38abaf607e0981d0215c8f499716560d - Sigstore transparency entry: 2106531880
- Sigstore integration time:
-
Permalink:
CoronRing/gs_prompt_manager@2ebc2d860a7ee266eea0cd42fb3cb739042d2193 -
Branch / Tag:
refs/tags/v0.0.9 - Owner: https://github.com/CoronRing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@2ebc2d860a7ee266eea0cd42fb3cb739042d2193 -
Trigger Event:
release
-
Statement type:
File details
Details for the file gs_prompt_manager-0.0.9-py3-none-any.whl.
File metadata
- Download URL: gs_prompt_manager-0.0.9-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bd4861d36d40cafdec2ffe2bbed88444c8b56f7114958c1a67f6e98bab1ee73
|
|
| MD5 |
8390a59ebf5b61e3247ce1a63505271d
|
|
| BLAKE2b-256 |
3477494884a3caafacdd07e62a6660961e150682a6ae6874d640a624be9ec4d7
|
Provenance
The following attestation bundles were made for gs_prompt_manager-0.0.9-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on CoronRing/gs_prompt_manager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gs_prompt_manager-0.0.9-py3-none-any.whl -
Subject digest:
3bd4861d36d40cafdec2ffe2bbed88444c8b56f7114958c1a67f6e98bab1ee73 - Sigstore transparency entry: 2106531975
- Sigstore integration time:
-
Permalink:
CoronRing/gs_prompt_manager@2ebc2d860a7ee266eea0cd42fb3cb739042d2193 -
Branch / Tag:
refs/tags/v0.0.9 - Owner: https://github.com/CoronRing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@2ebc2d860a7ee266eea0cd42fb3cb739042d2193 -
Trigger Event:
release
-
Statement type: