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.0.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.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptcraft_py-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 fe4b851ce6412d796dac4dc9628f25d6ae47a9d7e96d7707001a90122b2ceff9
MD5 45dc21c7285ac20f2b58424d2ea31d11
BLAKE2b-256 89d73835fcdd80371b9af0906025ed483046c2eb003926d2137cf1075ecc91d7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: promptcraft_py-0.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9bb79f8cedb7884fb3cd9ee369977ee1956f13e93e117db549ccda55ab7f1cbc
MD5 62903f819cf2e44a1efc3d7a76c7183c
BLAKE2b-256 d0724cb33d269b388ed1e232dff8c818e5a8c7b3a38eab6197f8db2169277b1e

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