A Python library for mastering AI prompts with versioning, templating, and testing
Project description
Promptplex
A Python library for mastering AI prompts with versioning, templating, and testing. Navigate the complexity of prompt engineering with ease.
Features
- Complex Template Management: Handle sophisticated prompt architectures
- Version Control: Track evolution of your prompt systems
- Validation Engine: Ensure template integrity and correctness
- Testing Matrix: Comprehensive testing across multiple scenarios
- Persistent Storage: Organize and preserve your prompt library
- Enterprise Patterns: Production-ready prompt templates
Installation
pip install promptplex
Quick Start
from promptplex import PromptManager, PromptTemplate
# Initialize Promptplex
manager = PromptManager()
# Build a complex template
template = PromptTemplate(
name="advanced_code_review",
template="Review this {language} code:\n\n{code}\n\nAnalyze: {focus_areas}",
variables=["language", "code", "focus_areas"],
description="Advanced code review system"
)
# Integrate into your workflow
manager.add_template(template)
# Execute with precision
review_prompt = template.render(
language="Python",
code="def hello(): print('world')",
focus_areas="performance, security, maintainability"
)
print(review_prompt)
Core Concepts
PromptTemplate
A PromptTemplate represents a reusable prompt with placeholders for variables:
template = PromptTemplate(
name="summarize",
template="Summarize this text in {length} sentences:\n\n{text}",
variables=["text", "length"],
version="1.0",
description="Text summarization template",
tags=["summarization", "text"]
)
PromptManager
The PromptManager handles storage, versioning, and organization of templates:
manager = PromptManager(storage_path=".prompts")
# Add templates
manager.add_template(template)
# Get templates
template = manager.get_template("summarize")
# List all templates
print(manager.list_templates())
# Export/import templates
manager.export_templates("my_prompts.yaml")
manager.import_templates("shared_prompts.yaml")
PromptTester
Test your templates with multiple inputs and compare variations:
from promptplex import PromptTester
tester = PromptTester(manager)
test_cases = [
{"text": "Long article text...", "length": "3"},
{"text": "Another article...", "length": "1"}
]
results = tester.test_template("summarize", test_cases)
# Compare different templates
comparison = tester.compare_templates(
["summarize_v1", "summarize_v2"],
test_cases
)
Built-in Templates
Promptplex includes enterprise-grade templates:
from promptplex import setup_builtin_templates
setup_builtin_templates(manager)
# Available templates:
# - code_review: For reviewing code
# - summarize: For text summarization
# - chat_assistant: For chat/assistant prompts
Advanced Usage
Template Validation
Templates are automatically validated when created:
# This will raise an error if template syntax is invalid
template.validate()
# Get a hash for change detection
hash_value = template.get_hash()
Custom Evaluators
Add custom evaluation logic to your tests:
def evaluate_summary(output, inputs):
# Custom logic to evaluate summary quality
return {
"length_appropriate": len(output.split()) < 100,
"contains_key_points": "important" in output.lower()
}
results = tester.test_template("summarize", test_cases, evaluator=evaluate_summary)
Working with Files
Templates are automatically saved to disk and loaded when needed:
# Templates are saved in .promptplex/ directory by default
manager = PromptManager() # Uses .promptplex/
manager = PromptManager("./my_prompts") # Custom directory
Development
Running Tests
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=promptplex
Code Formatting
# Format code
black promptplex tests
# Check types
mypy promptplex
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 promptplex-0.1.0.tar.gz.
File metadata
- Download URL: promptplex-0.1.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c51c59694281dde5b8d7452ff93860b3744c42721f92d8f2f182ef7c2f70e05
|
|
| MD5 |
f86739e7c00a67f7e82c2b493c024573
|
|
| BLAKE2b-256 |
d8dcbb5d5cb5129a266092e839abe54830eb5e5c0583677149b0cf5432f1d295
|
File details
Details for the file promptplex-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptplex-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3c40652c101be99e08987795171670339476b43b0f93a4d7a49a0eacc159b86
|
|
| MD5 |
8e5f2f811ebc33c706248e0c4f65c578
|
|
| BLAKE2b-256 |
0088a53b64c672d8f9b32c49f31d3868079165886728e13543979bc102d240e0
|