Skip to main content

Turn Python functions into LLM prompts

Project description

🔥 fireprompt

A lightweight Python library that turns functions into LLM prompts. Write Jinja2 templates, get type-safe Pydantic responses, and connect to 100+ providers via LiteLLM.

Links:

Quick Start

pip install fireprompt
from fireprompt import prompt, LLM
from pydantic import BaseModel

class ResearchResult(BaseModel):
    text: str

@prompt(model=LLM(name="gpt-4o"))
def research_topic(topic: str, level: str = "basic") -> ResearchResult:
    """
    - role: system
      content: You are a helpful research assistant.

    - role: user
      content: >
        Analyze {{ topic }} at a {{ level }} level.
        Provide a clear and informative overview.
    """
    ...

result = research_topic(topic="quantum computing")
print(result.text)
📤 Example Output
Quantum computing is a revolutionary computing paradigm that leverages quantum mechanics
principles to process information. Unlike classical computers that use bits (0 or 1),
quantum computers use qubits that can exist in superposition, representing both states
simultaneously. This enables quantum computers to solve certain complex problems
exponentially faster than classical computers, particularly in cryptography, optimization,
and molecular simulation.

Configuration

Custom Parameters

Use LLMConfig for universal parameters across all providers:

from fireprompt import prompt, LLM, LLMConfig
from pydantic import BaseModel

class Summary(BaseModel):
    text: str

@prompt(
    model=LLM(
        name="gpt-4o",
        config=LLMConfig(
            temperature=0.3,  # Lower = more focused (0-2)
            max_tokens=1000   # Max response length
        )
    )
)
def summarize(text: str, style: str = "professional") -> Summary:
    """
    - role: system
      content: You are an expert text summarizer.

    - role: user
      content: >
        Summarize this text in {{ style }} style:
        {{ text }}
    """
    ...

with open("article.txt") as f:
    result = summarize(text=f.read(), style="casual")

print(result.text)

Provider-Specific Parameters

Use extra for provider-specific options:

from fireprompt import prompt, LLM, LLMConfig
from pydantic import BaseModel

class Analysis(BaseModel):
    summary: str
    key_points: list[str]

@prompt(
    model=LLM(
        name="gpt-4o",
        config=LLMConfig(
            temperature=0.7,
            extra={
                "frequency_penalty": 0.5,  # OpenAI-specific
                "presence_penalty": 0.3
            }
        )
    )
)
def analyze(text: str) -> Analysis:
    """
    - role: user
      content: Analyze this text: {{ text }}
    """
    ...

Presets

Pre-configured settings for common use cases:

from fireprompt import prompt, LLM, LLMConfigPreset
from pydantic import BaseModel

class BlogPost(BaseModel):
    title: str
    content: str

@prompt(model=LLM(name="gpt-4o-mini", config=LLMConfigPreset.CREATIVE))
def write_blog(topic: str) -> BlogPost:
    """
    - role: system
      content: You are a creative blog writer.

    - role: user
      content: Write an engaging blog post about {{ topic }}.
    """
    ...

result = write_blog("Generative AI")
Preset Temperature Top P Best For
DEFAULT 0.7 - Balanced responses
CREATIVE 0.9 0.95 Writing, brainstorming
PRECISE 0.3 0.9 Technical analysis
DETERMINISTIC 0.0 1.0 Reproducible outputs

Callbacks

Post-process responses with on_complete:

from fireprompt import prompt, LLM
from pydantic import BaseModel

class Analysis(BaseModel):
    sentiment: str
    score: float

def log_result(result: Analysis) -> Analysis:
    print(f"✓ {result.sentiment} ({result.score})")
    return result

@prompt(model=LLM(name="gpt-4o-mini"), on_complete=log_result)
def analyze_sentiment(text: str) -> Analysis:
    """
    - role: user
      content: >
        Analyze sentiment: {{ text }}
        Return sentiment (positive/negative/neutral) and score (0-1).
    """
    ...

analyze_sentiment("I love this!")  # ✓ positive (0.95)

Debug Logging

import fireprompt

fireprompt.enable_logging()   # Enable debug mode
fireprompt.disable_logging()  # Disable debug mode

Features

Feature Description
🎯 Type-Safe Automatic Pydantic validation for structured outputs
Async First Auto-detects and handles sync/async functions
🎨 Jinja2 Templates Full template support with variables, filters, loops, conditionals
🔧 Flexible Config Universal parameters + provider-specific options via extra
📦 Presets Pre-configured settings for common use cases
🪝 Callbacks Post-process responses with on_complete
🔍 Debug Mode Built-in logging for development
🚀 Multi-Provider 100+ LLMs via LiteLLM (OpenAI, Anthropic, Gemini, etc.)

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

fireprompt-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

fireprompt-0.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file fireprompt-0.1.0.tar.gz.

File metadata

  • Download URL: fireprompt-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.10

File hashes

Hashes for fireprompt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 49ab51fb3446c8e11a767a36a03c4b88c0b3e23177da6dc1f6f72f31f260b681
MD5 62bc7ecbfa66615687683a96999ee4a2
BLAKE2b-256 36254313adc0511dc90deca2ae2ec02b4cc7f38f33fa70bc4c36ef9bd5e43f71

See more details on using hashes here.

File details

Details for the file fireprompt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: fireprompt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.10

File hashes

Hashes for fireprompt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72de453e6a3e9269b6dbecede2dea1d407ac3c8d471cc617ca1b902bdb057ec8
MD5 7cf7a8422cfa382df10b0f6341bbf06d
BLAKE2b-256 273b04decffd96f3a0331031c498eb8b8d082b9e2d0dbe2ff08f569910305299

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