Skip to main content

A lightweight Python package for managing and organizing prompt templates with auto-discovery and variable substitution.

Project description

gs_prompt_manager

PyPI version Python Support License Tests

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_group decorator
  • Validation: built-in checks for prompt pieces, metadata, and required fields
  • Extensible: subclass PromptBase to 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:

  1. Prompt pieces{variable}, user-provided at call time (or via defaults).
  2. 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

gs_prompt_manager-0.0.6.tar.gz (43.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gs_prompt_manager-0.0.6-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file gs_prompt_manager-0.0.6.tar.gz.

File metadata

  • Download URL: gs_prompt_manager-0.0.6.tar.gz
  • Upload date:
  • Size: 43.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for gs_prompt_manager-0.0.6.tar.gz
Algorithm Hash digest
SHA256 d9d67191d2ce4af09d019cbdb58d068d620e23e577363109f18c9fc32ee30b48
MD5 4cb67fccccf5dcc0854efc06d9c073a8
BLAKE2b-256 b449ced0b3737c6a3369c02978de68501e4cfaf7d7c0f70f33bc6c72197489ec

See more details on using hashes here.

File details

Details for the file gs_prompt_manager-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for gs_prompt_manager-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 925996a34bbf1ea3fb316b80ad419d539616b6d70a2f3fa65bb47ba989bd55c5
MD5 8d51b595457953b9c48e2cfdf7427d07
BLAKE2b-256 0c546257c9c0450ac748f758393f88230f4378b06230615df82a32c2334a0077

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page