A lightweight toolkit for prompt engineering, optimization, and evaluation
Project description
🎯 PromptCraft
A lightweight Python toolkit for prompt engineering, optimization, and evaluation.
PromptCraft helps developers build, test, and refine prompts for LLMs with a clean, composable API.
✨ Features
- Prompt Builder — Chain instructions, examples, and variables with a fluent API
- Template System — Reusable prompt templates with variable interpolation
- Optimizer — Automatically refine prompts using scoring and iteration
- Evaluator — Score prompt quality across clarity, specificity, and completeness
- Multi-provider — Works with OpenAI, Anthropic, and any OpenAI-compatible API
- Zero dependencies — Core library has no external dependencies
🚀 Quick Start
pip install promptcraft
from promptcraft import PromptBuilder, Template
# Build a prompt
prompt = (
PromptBuilder()
.system("You are a helpful coding assistant.")
.instruction("Explain the following concept clearly.")
.variable("concept", "dependency injection")
.examples([
{"input": "What is recursion?", "output": "Recursion is when a function calls itself..."}
])
.build()
)
print(prompt)
Using Templates
from promptcraft import Template
# Define a reusable template
review_template = Template(
name="code_review",
system="You are a senior code reviewer.",
instruction="Review the following {language} code for bugs and improvements.",
variables=["language", "code"]
)
# Render with specific values
prompt = review_template.render(
language="Python",
code="def add(a, b): return a"
)
Optimizing Prompts
from promptcraft import Optimizer
optimizer = Optimizer(
metric="relevance",
iterations=5
)
optimized = optimizer.optimize(
prompt="Explain {topic}",
test_cases=[
{"topic": "quantum computing", "expected_keywords": ["qubit", "superposition"]},
{"topic": "machine learning", "expected_keywords": ["model", "training"]},
]
)
print(f"Score improved from {optimized.initial_score:.2f} to {optimized.final_score:.2f}")
Evaluating Prompts
from promptcraft import Evaluator
evaluator = Evaluator()
result = evaluator.score(
prompt="Write a function that sorts a list",
criteria=["clarity", "specificity", "completeness"]
)
print(f"Overall: {result.overall:.2f}")
print(f"Clarity: {result.scores['clarity']:.2f}")
📦 Installation
# From PyPI
pip install promptcraft
# From source
git clone https://github.com/USER/PromptCraft.git
cd PromptCraft
pip install -e .
🧪 Running Tests
# Run all tests
pytest
# With coverage
pytest --cov=promptcraft --cov-report=term-missing
📚 Documentation
🤝 Contributing
Contributions are welcome! Please read CONTRIBUTING.md for details.
📄 License
This project is licensed under the MIT License — see LICENSE 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 promptcraft_py-0.1.0.tar.gz.
File metadata
- Download URL: promptcraft_py-0.1.0.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d97ff420a036619b72f513db3e0fcecbc7b0ff67d48fc21c33f2d653fc106bd4
|
|
| MD5 |
f89313b02cf9aea1da27f521b5c1ad5d
|
|
| BLAKE2b-256 |
6083dba84638d01dfdae6501a29cf97394e061d506fa84724d8b1fa1403e3fe6
|
File details
Details for the file promptcraft_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: promptcraft_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26c52ba018038e16693962273575082f2682fb0637deeacfa363413d9a97ae18
|
|
| MD5 |
a93c0b79717d248eee6ee10d317ba569
|
|
| BLAKE2b-256 |
59e5cc8dad0ab11fe495686d1ae3bc0ab57c18ec0e98aff8392fa6c896eec23a
|