Python SDK

Install and use the Refrase Python package to optimize prompts from your Python applications.

Installation

bash

Quick Start

python

API Reference

refrase.adapt(prompt, model, task, user_prompt)

Adapt a system prompt for a specific model and task type.

ParameterTypeDescription
promptstrThe system prompt to optimize
modelstrTarget model identifier
taskTaskTypeOptional. Task type for context-aware optimization
user_promptstrOptional. Example user message for calibration

Returns an AdaptResult object.

refrase.list_models()

Returns a list of all supported model configurations as dictionaries containing id, name, provider, and capabilities.

TaskType Enum

class TaskType(str, Enum):
    CHAT = "chat"
    CODE = "code"
    ANALYSIS = "analysis"
    CREATIVE = "creative"
    EXTRACTION = "extraction"
    SUMMARIZATION = "summarization"

Change Dataclass

@dataclass
class Change:
    type: str        # "add" | "remove" | "modify" | "reorder"
    description: str # Human-readable explanation
    before: str      # Original text (empty for additions)
    after: str       # Modified text (empty for removals)
    reason: str      # Why this change improves the prompt