Turn Python functions into LLM prompts
Project description
🔥 fireprompt
A lightweight Python library that turns your functions into LLM prompts. Write Jinja2 templates, get type-safe Pydantic responses, and connect to 100+ providers via LiteLLM.
FirePrompt is a framework, not a prompt library. You define your own functions (
analyze_sentiment,extract_data,generate_code- whatever you need). FirePrompt handles the LLM integration, type validation, and templating.
Links:
Quick Start
pip install fireprompt
Setup & Authentication
FirePrompt uses LiteLLM to access 100+ LLM providers (OpenAI, Anthropic, Google, Azure, AWS Bedrock, and more).
To get started: Set up your provider's API key as an environment variable. Each provider has different requirements.
📚 Follow the setup guide for your provider: 👉 LiteLLM Provider Documentation
Example for OpenAI:
export OPENAI_API_KEY="sk-..."
Then in your code:
model=LLM(name="openai/gpt-4o")
How It Works
- Write a Python function - Define what you want (e.g.,
research_topic,analyze_sentiment,generate_code) - Add the
@promptdecorator - Tell FirePrompt which LLM to use - Write your prompt in the docstring - Use Jinja2 templates to inject variables
- Call it like a normal function - FirePrompt handles the LLM call and returns typed results
Example: Here's a custom prompt function you might create:
from fireprompt import prompt, LLM
from pydantic import BaseModel
class ResearchResult(BaseModel):
text: str
@prompt(
model=LLM(
name="openai/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)
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="anthropic/claude-3-5-sonnet-20241022",
config=LLMConfig(
temperature=0.3, # Lower = more focused (0-2)
max_tokens=1000 # Max response length
)
)
)
def summarize(text: str, style: str = "professional", keywords: list[str] = []) -> Summary:
"""
- role: system
content: You are an expert text summarizer.
- role: user
content: |
Summarize this text in {{ style | upper }} style.
{% if keywords %}
Focus on these keywords:
{% for keyword in keywords %}
- {{ keyword | title }}
{% endfor %}
{% endif %}
Text:
{{ text }}
"""
...
with open("article.txt") as f:
result = summarize(
text=f.read(),
style="casual",
keywords=[
"AI",
"Machine Learning",
"Innovation"
]
)
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="openai/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 }}
"""
...
result = analyze("Your text here...")
print(result)
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="gemini/gemini-1.5-pro",
config=LLMConfigPreset.CREATIVE
)
)
def write_blog(topic: str, sections: list[str] = []) -> BlogPost:
"""
- role: user
content: |
Write an engaging blog post about {{ topic | title }}.
{% if sections | length > 0 %}
Include these sections:
{% for section in sections %}
{{ loop.index }}. {{ section }}
{% endfor %}
{% else %}
Create your own structure.
{% endif %}
"""
...
result = write_blog("Generative AI", sections=["Introduction", "Key Benefits", "Use Cases"])
print(result)
| 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(
on_complete=log_result,
model=LLM(
name="openai/gpt-4o-mini"
)
)
def analyze_sentiment(text: str) -> Analysis:
"""
- role: user
content: >
Analyze sentiment: {{ text }}
Return sentiment (positive/negative/neutral) and score (0-1).
"""
...
result = analyze_sentiment("I love this!") # ✓ positive (0.95)
print(result)
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 (Claude), Google (Gemini), Azure, AWS Bedrock, and more |
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fireprompt-0.1.9.tar.gz.
File metadata
- Download URL: fireprompt-0.1.9.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d1421076e256d1c842179061949584220f42f9bcd1ae3a20daf44ea529fbffe3
|
|
| MD5 |
44285573493839aa73ecb3ea44c092d6
|
|
| BLAKE2b-256 |
1100a8b7ff80a3d62411a14a31db1d57c2c83143070f81d9bb29139f34fa1e68
|
Provenance
The following attestation bundles were made for fireprompt-0.1.9.tar.gz:
Publisher:
release-pypi.yaml on AlonLiber/fireprompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fireprompt-0.1.9.tar.gz -
Subject digest:
d1421076e256d1c842179061949584220f42f9bcd1ae3a20daf44ea529fbffe3 - Sigstore transparency entry: 820983042
- Sigstore integration time:
-
Permalink:
AlonLiber/fireprompt@d3d32e46ad9926bab4bfcfe79ddf81c0d8e2ebc7 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AlonLiber
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@d3d32e46ad9926bab4bfcfe79ddf81c0d8e2ebc7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fireprompt-0.1.9-py3-none-any.whl.
File metadata
- Download URL: fireprompt-0.1.9-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed698ce9a1ce06be4c1c9d72ea3f0a5fab413f6beb52e5f0044b0b1eeb29041d
|
|
| MD5 |
99d473014df253dad8d3394bfdf0fb1f
|
|
| BLAKE2b-256 |
ab3d8368141c3f909ea5fa4252ac736ec7b8d7ea685080bdc126bf996d5cb72c
|
Provenance
The following attestation bundles were made for fireprompt-0.1.9-py3-none-any.whl:
Publisher:
release-pypi.yaml on AlonLiber/fireprompt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fireprompt-0.1.9-py3-none-any.whl -
Subject digest:
ed698ce9a1ce06be4c1c9d72ea3f0a5fab413f6beb52e5f0044b0b1eeb29041d - Sigstore transparency entry: 820983045
- Sigstore integration time:
-
Permalink:
AlonLiber/fireprompt@d3d32e46ad9926bab4bfcfe79ddf81c0d8e2ebc7 -
Branch / Tag:
refs/tags/v0.1.9 - Owner: https://github.com/AlonLiber
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-pypi.yaml@d3d32e46ad9926bab4bfcfe79ddf81c0d8e2ebc7 -
Trigger Event:
push
-
Statement type: