Skip to main content

馃幆 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.

Metadata

Release files for promptcraft-py 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for promptcraft-py 0.2.1
File Size Uploaded Provenance Actions
promptcraft_py-0.2.1.tar.gz 17.4 kB Without provenance Details for promptcraft_py-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for promptcraft-py 0.2.1
File Interpreter ABI Platform Actions
promptcraft_py-0.2.1-py3-none-any.whl Python 3 none any Details for promptcraft_py-0.2.1-py3-none-any.whl

Total release size: 33.6 kB

Release files / promptcraft_py-0.2.1.tar.gz

Download URL promptcraft_py-0.2.1.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d6a1975551a0b32bcb2a70920dea5b7a824ef06204552889bccf9167db458f7b
BLAKE2b-256 checksum
How to use checksums
ff4c8809d6a05419dc2e12c0fc344dbe2bdfe052ebc295d9bfbaa5edaa7523cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / promptcraft_py-0.2.1-py3-none-any.whl

Download URL promptcraft_py-0.2.1-py3-none-any.whl
Size 16.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
212b849662ea6dd89ebfac81e6c20c2a292f1d79f6dea05c2217c6f6d982252d
BLAKE2b-256 checksum
How to use checksums
0d8d2452840c80b10a1415bcaa037384789350be21c62c76e5b295754e2e6805
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for promptcraft-py 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page