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 manages prompt classes that inherit from PromptBase.

✨ Features

  • 🔍 Auto-discovery: Automatically finds and loads prompt classes from specified directories
  • 📦 Template Management: Define reusable prompt templates with variable substitution
  • 🎯 Type Safety: Built-in validation for prompt pieces and metadata
  • 🔧 Flexible: Support for both chat and system prompts
  • 📝 Metadata: Rich metadata support for prompts (tags, tools, examples, etc.)
  • 🔄 Predefined Macros: Support for datetime and custom macro substitution
  • 🏗️ Extensible: Easy to subclass and customize for specific use cases

🚀 Quick Start

Installation

pip install gs-prompt-manager

Basic Usage

Step 1: Create a Prompt

from gs_prompt_manager import PromptBase

class GreetingPrompt(PromptBase):
    """A simple greeting prompt."""

    def set_prompt_chat(self):
        return "Hello, {name}! Welcome to {place}."

    def set_prompt_system(self):
        return "You are a friendly assistant."

    def set_name(self):
        self.name = "GreetingPrompt"

# Use the prompt
prompt = GreetingPrompt()
print(prompt.get_prompt_chat({"name": "Alice", "place": "Wonderland"}))
# Output: Hello, Alice! Welcome to Wonderland.

Step 2: Manage Multiple Prompts

from gs_prompt_manager import PromptManager

# Auto-discover prompts in a directory
manager = PromptManager(prompt_paths="./my_prompts")

# List available prompts
print(manager.get_prompt_names())

# Get a specific prompt
greeting = manager.get_prompt("GreetingPrompt")
result = greeting.get_prompt_chat({"name": "Bob"})

📖 Documentation

💡 Key Concepts

PromptBase

The base class for all prompt templates. Subclass it to create custom prompts:

class MyPrompt(PromptBase):
    def set_prompt_chat(self):
        return "Your template with {variables}"

    def set_name(self):
        self.name = "MyPrompt"

PromptManager

Automatically discovers and manages multiple prompt classes:

manager = PromptManager(prompt_paths=["./prompts", "./more_prompts"])
prompt = manager.get_prompt("MyPrompt")

Variable Substitution

Two types of variables are supported:

  1. Prompt Pieces - {variable}: User-provided values
  2. Predefined Macros - <<MACRO>>: System-generated values
def set_prompt_chat(self):
    return "User {name} logged in at <<DATETIME>>"

🎯 Use Cases

  • LLM Application Development: Manage prompts for ChatGPT, Claude, etc.
  • Prompt Engineering: Organize and version control prompt templates
  • Multi-Agent Systems: Define prompts for different AI agents
  • A/B Testing: Compare different prompt variations
  • Prompt Libraries: Build reusable prompt collections

📊 Requirements

  • Python 3.8+
  • regex >= 2022.1.18

🤝 Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

👤 Author

Guan Huang

🔗 Links

⭐ Star History

If you find this project helpful, please consider giving it a star on GitHub!

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.5.tar.gz (30.6 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.5-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gs_prompt_manager-0.0.5.tar.gz
  • Upload date:
  • Size: 30.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gs_prompt_manager-0.0.5.tar.gz
Algorithm Hash digest
SHA256 80e1f70b68bba9251cafa65c47a3bb34c3ea2ac13c786e1bfc4f4fede50b376e
MD5 4a9c5519ffc3f77fddaa633ffd08d383
BLAKE2b-256 c5733bd101518369f38959b910e7414708a7bb2022e06dfe9eadf60a615a87c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for gs_prompt_manager-0.0.5.tar.gz:

Publisher: publish-to-pypi.yml on CoronRing/gs_prompt_manager

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for gs_prompt_manager-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 92331a6dc8965e38f5cb4325bfb723fb350cc339c984f410b89b20cf344e18f1
MD5 9e145bc014f20982c47902b392eebb68
BLAKE2b-256 90887ac58f74ba2059ab6e6015c76c1e8796d29a61cf085d216070151cf6a473

See more details on using hashes here.

Provenance

The following attestation bundles were made for gs_prompt_manager-0.0.5-py3-none-any.whl:

Publisher: publish-to-pypi.yml on CoronRing/gs_prompt_manager

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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