Skip to main content

A lightweight toolkit for prompt engineering, optimization, and evaluation

Project description

馃幆 PromptCraft

CI Python License: MIT Downloads

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-py
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-py

# 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptcraft_py-0.2.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

promptcraft_py-0.2.1-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file promptcraft_py-0.2.1.tar.gz.

File metadata

  • Download URL: promptcraft_py-0.2.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for promptcraft_py-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d6a1975551a0b32bcb2a70920dea5b7a824ef06204552889bccf9167db458f7b
MD5 f45735353b210f3ead833ae3154ac6b8
BLAKE2b-256 ff4c8809d6a05419dc2e12c0fc344dbe2bdfe052ebc295d9bfbaa5edaa7523cf

See more details on using hashes here.

File details

Details for the file promptcraft_py-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: promptcraft_py-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for promptcraft_py-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 212b849662ea6dd89ebfac81e6c20c2a292f1d79f6dea05c2217c6f6d982252d
MD5 031e922084c183d35772444cf9947d33
BLAKE2b-256 0d8d2452840c80b10a1415bcaa037384789350be21c62c76e5b295754e2e6805

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