Official Python client for PLP (Prompt Library Protocol)
Project description
plp-client
Official Python client for PLP (Prompt Library Protocol).
Installation
pip install plp-client
Quick Start
from plp_client import PLPClient, PromptInput
# Initialize client
client = PLPClient("https://prompts.goreal.ai", api_key="your-api-key")
# Get latest version of a prompt
prompt = client.get("marketing/welcome-email")
print(prompt.content) # "Hello {{name}}..."
# Get specific version
old_prompt = client.get("marketing/welcome-email", "1.0.0")
# Save a new prompt
client.put("support/faq-bot", PromptInput(
content="You are a helpful FAQ bot. Answer: {{question}}",
meta={"version": "1.0.0", "author": "yoad"}
))
# Delete a prompt
client.delete("deprecated/old-prompt")
API Reference
PLPClient
Constructor
PLPClient(base_url: str, api_key: Optional[str] = None,
headers: Optional[Dict[str, str]] = None, timeout: int = 10)
Parameters:
base_url(str): Base URL of the PLP serverapi_key(str, optional): Optional Bearer token for authenticationheaders(dict, optional): Additional HTTP headerstimeout(int): Request timeout in seconds (default: 10)
Methods
get(prompt_id, version=None)
Retrieve a prompt by ID and optional version.
def get(prompt_id: str, version: Optional[str] = None) -> PromptEnvelope
prompt_id(str): Unique prompt identifier (e.g.,"marketing/welcome-email")version(str, optional): Optional version string (e.g.,"1.2.0"). If omitted, returns latest.
Returns: PromptEnvelope
Raises: PLPError if not found (404) or other errors
put(prompt_id, input)
Create or update a prompt (idempotent upsert).
def put(prompt_id: str, input: PromptInput) -> PromptEnvelope
prompt_id(str): Unique prompt identifierinput(PromptInput): Object withcontentand optionalmeta
Returns: The saved PromptEnvelope
delete(prompt_id)
Delete a prompt and all its versions.
def delete(prompt_id: str) -> None
prompt_id(str): Unique prompt identifier
Returns: None (204 No Content on success)
Aliases
fetch(prompt_id, version=None) # Alias for get()
save(prompt_id, input) # Alias for put()
Data Classes
PromptEnvelope
class PromptEnvelope:
id: str
content: str
meta: Dict[str, Any]
PromptInput
class PromptInput:
content: str
meta: Dict[str, Any]
Error Handling
from plp_client import PLPClient, PLPError
client = PLPClient("https://prompts.goreal.ai")
try:
prompt = client.get("missing/prompt")
except PLPError as e:
print(f"Error: {e}")
print(f"Status code: {e.status_code}")
Examples
Using with OpenAI
from plp_client import PLPClient
from openai import OpenAI
plp = PLPClient("https://prompts.goreal.ai")
openai = OpenAI()
prompt = plp.get("assistant/code-reviewer")
response = openai.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt.content}],
temperature=prompt.meta.get("model_config", {}).get("temperature", 0.7)
)
print(response.choices[0].message.content)
Using with Anthropic
from plp_client import PLPClient
import anthropic
plp = PLPClient("https://prompts.goreal.ai")
client = anthropic.Anthropic()
prompt = plp.get("creative/story-generator")
message = client.messages.create(
model="claude-3-opus-20240229",
max_tokens=prompt.meta.get("model_config", {}).get("max_tokens", 1024),
messages=[{"role": "user", "content": prompt.content}]
)
print(message.content)
Context Manager
from plp_client import PLPClient
with PLPClient("https://prompts.goreal.ai") as client:
prompt = client.get("my/prompt")
print(prompt.content)
# Session is automatically closed
Development
# Install dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run tests with coverage
pytest --cov=plp_client
# Format code
black src/ tests/
# Type checking
mypy src/
License
MIT © GoReal.AI
Contributing
See CONTRIBUTING.md
Learn More
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 plp_client-1.0.0.tar.gz.
File metadata
- Download URL: plp_client-1.0.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
99ae8b28bdb0085828f11a09a8a6786a087ad818b5e119511c0845d40571e877
|
|
| MD5 |
55f9b9948a457aab0ba7d1b8d44c6a4d
|
|
| BLAKE2b-256 |
f037a8ce39198a52f6965a8c4c829d43e7b2a3e7097bc77c56a57f97b086b541
|
File details
Details for the file plp_client-1.0.0-py3-none-any.whl.
File metadata
- Download URL: plp_client-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
601c6b897f470b278b80c4a04eaee2663925ecb65d2af9e2f56af75a69682447
|
|
| MD5 |
0d800024408c73e7190088d3f3325a4a
|
|
| BLAKE2b-256 |
b0aee3e723c99537c55cbf9e2730e05985ef9bd2a2fc5e7d929821c0696f1045
|