Skip to main content

Python SDK for PromptOps - AI Prompt Management Platform

Project description

PromptOps Python SDK

Python SDK for PromptOps — AI Prompt Management Platform.

Installation

pip install promptops

Quick Start

from promptops import PromptOps

po = PromptOps(api_key="pop_sk_xxx")
config = po.get_prompt("customer-support", label="prod")
print(config.system_prompt)

# Context manager (recommended — ensures cleanup)
with PromptOps(api_key="pop_sk_xxx") as po:
    config = po.get_prompt("customer-support")
    print(config.system_prompt)

Variable Substitution

from promptops import PromptOps

with PromptOps(api_key="pop_sk_xxx") as po:
    config = po.get_prompt("customer-support")

    if config.user_prompt_template:
        message = PromptOps.substitute(
            config.user_prompt_template,
            {"customer_name": "Alice", "issue": "login problem"},
        )
        print(message)

Configuration Options

from promptops import PromptOps, PromptConfig

# Fallback used when API is unreachable and cache is empty
fallback_config = PromptConfig(
    slug="customer-support",
    version=1,
    type="text",
    system_prompt="You are a helpful assistant.",
    user_prompt_template="Help {{customer_name}} with: {{issue}}",
    content=None,
    config={"model": "gpt-4o-mini", "provider": "openai", "temperature": 0.7, "max_tokens": 1024},
    variables=[{"name": "customer_name"}, {"name": "issue"}],
    updated_at="2024-01-01T00:00:00Z",
)

po = PromptOps(
    api_key="pop_sk_xxx",
    base_url="https://promptsops.com",   # default
    refresh_interval=60,                  # seconds, default 60
    fallback={"customer-support": fallback_config},
)

Manual Cache Refresh

with PromptOps(api_key="pop_sk_xxx") as po:
    # Refresh a specific prompt
    po.refresh("customer-support")

    # Refresh all cached prompts
    po.refresh()

PromptConfig Fields

Field Type Description
slug str Prompt identifier
version int Prompt version number
type str "text" or "chat"
system_prompt str | None System prompt text
user_prompt_template str | None User prompt with {{variable}} placeholders
content Any Chat-type structured content
config dict Model config: model, provider, temperature, max_tokens
variables list[dict] Variable definitions: name, optional description
updated_at str ISO 8601 timestamp of last update

Caching Behaviour

The SDK uses a 3-tier fallback strategy on every get_prompt() call:

  1. In-memory cache — returns immediately if the entry is younger than refresh_interval seconds.
  2. API fetch — sends a request with If-None-Match (ETag); a 304 Not Modified response refreshes the timestamp without re-parsing the body.
  3. User-provided fallback — returned when both the cache and API are unavailable.

A background daemon thread automatically refreshes all cached prompts every refresh_interval seconds. The cache is protected by a threading.Lock and is safe for concurrent use.

License

Apache-2.0

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

promptops_sdk-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.

promptops_sdk-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptops_sdk-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.11.9

File hashes

Hashes for promptops_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 01ae90c9468e253274a0bf674f4e91d0fa65cda7ebcc5d9da2660d337ce0d793
MD5 6c8ab38e2ca93cd56cef273a735d05cf
BLAKE2b-256 9410a8ddedff00557437fff99a1e06f305e228bca909f4c6b2c7649e65d10f7e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for promptops_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 35028fab2ead1c59d44a72e4cd44398a480b51a1cb6ec64556a82281e840f3a3
MD5 5a342fd505a5fe1132178715e3cbd4f5
BLAKE2b-256 d8bfcc7e247f6bc818951b7045142e3e802d493579ba97825d8b91c6ec3cd309

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