Skip to main content

Structured Prompt Engineering for LLM Apps

Project description


⚙️ PromptKit

A production-grade library for structured LLM prompt engineering.

Cat Typing on Computer
Explore the docs »

Report Bug · Request Feature

PyPI PyPI - Python Version CI License


Why PromptKit?

Managing prompts for Large Language Models can quickly become messy. Hardcoding prompts as f-strings mixes logic with presentation, lacks validation, and makes reuse difficult.

PromptKit solves this by treating your prompts as structured, version-controlled assets. By defining prompts in YAML files, you get:

  • Clean Separation: Prompt templates are separate from application code
  • Safety & Reliability: Built-in validation ensures prompts receive correct inputs
  • Reusability: Define a prompt once, use it anywhere
  • Clarity: Human-readable format anyone can understand

Features

  • 📝 Declarative: Define prompts in YAML with Jinja2 templating
  • 🔍 Validation: Pydantic-based input validation before rendering
  • 🏗️ Engine Abstraction: Supports OpenAI and Ollama
  • 💰 Cost Estimation: Estimate token counts and costs before execution
  • 🖥️ CLI: Render, run, lint, and inspect prompts from terminal
  • 🧪 Typed: Full type hints for IDE support

Quick Start

Installation

pip install promptkit-core

Define a Prompt

Create greet.yaml:

name: greet
description: Generates a personalized greeting
template: |
  Hello {{ name }}!
  
  {% if context %}
  Context: {{ context }}
  {% endif %}
  
  How can I help you today?

input_schema:
  name: str
  context: "str | None"

Use in Python

from promptkit import load_prompt, run_prompt, OpenAIEngine

prompt = load_prompt("greet.yaml")

engine = OpenAIEngine(api_key="sk-...")

response = run_prompt(prompt, {"name": "Alice"}, engine)
print(response)

Use the CLI

export OPENAI_API_KEY="sk-..."

# Run the prompt
promptkit run greet.yaml --name Alice

# Render template without calling AI
promptkit render greet.yaml --name Alice

# Validate prompt structure
promptkit lint greet.yaml

# Get prompt information
promptkit info greet.yaml

# Estimate costs
promptkit cost greet.yaml --model gpt-4 --name Alice

Prompt Structure

Every prompt YAML file contains:

  • name: Unique identifier
  • description: Human-readable description
  • template: Jinja2 template with variables
  • input_schema: Type definitions for inputs

Input Schema Types

input_schema:
  name: str              # Required string
  age: int               # Required integer
  score: float           # Required float
  active: bool           # Required boolean
  tags: list             # Required list
  data: dict             # Required dictionary
  email: "str | None"    # Optional string

Engines

OpenAI

from promptkit import OpenAIEngine

engine = OpenAIEngine(
    api_key="sk-...",
    model="gpt-4o-mini",
    temperature=0.7,
    max_tokens=1000
)

Ollama (Local)

from promptkit.engines import OllamaEngine

engine = OllamaEngine(
    model="llama2",
    temperature=0.7
)

Documentation

See the documentation for detailed guides and API reference.

Contributing

Contributions welcome. See CONTRIBUTING.md for guidelines.

License

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

promptkit_core-0.1.1.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

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

promptkit_core-0.1.1-py3-none-any.whl (22.8 kB view details)

Uploaded Python 3

File details

Details for the file promptkit_core-0.1.1.tar.gz.

File metadata

  • Download URL: promptkit_core-0.1.1.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for promptkit_core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 05e5e1483a3f5874cec6f79862d219711bdbc66d48b9560e17fe255c841fe319
MD5 4c6f2700d3b7191bb9b2b7a81e02698f
BLAKE2b-256 71332f63d90f0258d45ec98fbbc74496200845f0a6ee3cb29fb1669841eba4af

See more details on using hashes here.

File details

Details for the file promptkit_core-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: promptkit_core-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for promptkit_core-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c27477cff7bedfb8b5240eee8b0f22baee7efab3e4e4fbd5291fa34d5109070d
MD5 44a9b9ab68eb2674a08a79be478f0d80
BLAKE2b-256 173917a26d5f5847e564c2789c193ee9e7a648a419ee72c76bb0542b217dea3a

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