Python SDK for Dr-Prompt - A lightweight, version-controlled prompt management system
Project description
drprompt
Python SDK for Dr-Prompt — a lightweight, version-controlled prompt management system.
Store, version, and serve your LLM prompts through a clean API. Use this SDK to fetch prompts at runtime, render templates, track token usage, and more.
Installation
pip install drprompt
Quick Start
from drprompt import DrPrompt
# Authenticate with an API key (generate one from Settings > API Keys in the UI)
client = DrPrompt("https://your-instance.com", api_key="drp_your_api_key")
# Fetch a prompt by UID
prompt = client.get_prompt("550e8400-e29b-41d4-a716-446655440000")
# Render template variables
rendered = prompt.render({"topic": "Python", "style": "concise"})
print(rendered)
Usage with OpenAI
from drprompt import DrPrompt
from openai import OpenAI
drp = DrPrompt("https://your-instance.com", api_key="drp_your_api_key")
openai = OpenAI()
prompt = drp.get_prompt("550e8400-e29b-41d4-a716-446655440000")
system_prompt = prompt.render({"topic": "Python"})
response = openai.chat.completions.create(
model="gpt-4",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": "Explain decorators"}
]
)
# Report token usage back to Dr-Prompt
drp.report_usage(
prompt=prompt.uid,
model="gpt-4",
input_tokens=response.usage.prompt_tokens,
output_tokens=response.usage.completion_tokens
)
Usage with Anthropic
from drprompt import DrPrompt
import anthropic
drp = DrPrompt("https://your-instance.com", api_key="drp_your_api_key")
claude = anthropic.Anthropic()
prompt = drp.get_prompt("550e8400-e29b-41d4-a716-446655440000")
system_prompt = prompt.render({"topic": "Python"})
response = claude.messages.create(
model="claude-sonnet-4-5-20250929",
max_tokens=1024,
system=system_prompt,
messages=[{"role": "user", "content": "Explain decorators"}]
)
drp.report_usage(
prompt=prompt.uid,
model="claude-sonnet-4-5",
input_tokens=response.usage.input_tokens,
output_tokens=response.usage.output_tokens
)
Authentication
API key (recommended)
Generate a key from the Dr-Prompt web UI under Settings > API Keys:
client = DrPrompt("https://your-instance.com", api_key="drp_your_api_key")
Or load from an environment variable:
import os
client = DrPrompt("https://your-instance.com", api_key=os.environ["DRPROMPT_API_KEY"])
Username / password
client = DrPrompt("https://your-instance.com")
client.login("username", "password")
JWT token
client = DrPrompt("https://your-instance.com", token="your-jwt-token")
Features
Prompt CRUD
# List all prompts
for p in client.list_prompts():
print(f"{p.uid}: {p.name}")
# Create
prompt = client.create_prompt(
name="Code Reviewer",
content="You are a {{language}} code reviewer. Review for {{focus}}.",
description="Reviews code for best practices"
)
# Update (creates a new version)
client.update_prompt(prompt.uid, content="Updated content...")
# Delete
client.delete_prompt(prompt.uid)
Version History
versions = client.get_prompt_versions(prompt.uid)
v1 = client.get_prompt_version(prompt.uid, version=1)
print(v1.content)
Template Variables
prompt = client.get_prompt("550e8400-e29b-41d4-a716-446655440000")
# Extract variable names
variables = prompt.get_variables() # ["language", "focus"]
# Render
rendered = prompt.render({"language": "Python", "focus": "security"})
Collections
collections = client.list_collections()
collection = client.create_collection(
name="Code Review Prompts",
description="Prompts for code review tasks",
color="#00ff88"
)
client.add_prompts_to_collection(collection.id, prompt_ids=[1, 2, 3])
Usage Tracking
# Report usage after an LLM call
client.report_usage(
prompt=prompt.uid,
model="gpt-4",
input_tokens=150,
output_tokens=320
)
# Get stats
stats = client.get_usage_stats()
print(f"Total calls: {stats.total_calls}")
print(f"Total tokens: {stats.total_tokens}")
Smart Features
Requires an OpenAI API key configured on your Dr-Prompt instance.
# Analyze prompt quality
analysis = client.analyze_prompt(prompt.uid)
# Get AI-suggested improvements
improved = client.improve_prompt(prompt.uid, focus="clarity")
# Generate variations
variations = client.generate_variations(prompt.uid, count=3, style="formal")
Error Handling
from drprompt import DrPrompt, AuthenticationError, NotFoundError, APIError
client = DrPrompt("https://your-instance.com", api_key="drp_your_api_key")
try:
prompt = client.get_prompt("nonexistent")
except AuthenticationError:
print("Invalid or expired API key")
except NotFoundError:
print("Prompt not found")
except APIError as e:
print(f"API error ({e.status_code}): {e.message}")
Configuration
client = DrPrompt(
base_url="https://your-instance.com",
api_key="drp_your_api_key", # or token="jwt-token"
timeout=30, # request timeout in seconds
)
Links
- Dr-Prompt GitHub — self-host the server
- API Docs — Swagger UI on every instance at
/docs - Issues — bug reports and feature requests
License
MIT
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 drprompt-0.1.1.tar.gz.
File metadata
- Download URL: drprompt-0.1.1.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fd61bb29f408f95ead6a7ab58b74d34a589428603cac5b4eeebc1b0ef5daf946
|
|
| MD5 |
05ac4b44ab0fee617bb6c5a08d6e1773
|
|
| BLAKE2b-256 |
c91f5b70b7b49126e43ac6220c9545300e43f0f7b570fce15e9f7ad412660962
|
File details
Details for the file drprompt-0.1.1-py3-none-any.whl.
File metadata
- Download URL: drprompt-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4310df7a04897440299506666bf04722c0af6d8d4419f7f77a8037e6cb6240f
|
|
| MD5 |
6eeda53b3e1e0ad115d6c738d9548eb0
|
|
| BLAKE2b-256 |
3e2ea4c7912e02d64666e59cbdd39c6cf4c9318fd2ffa3c64deea950560a32df
|