Skip to main content

promptkeep

Prompts as first-class objects: named, versioned templates with lineage tracked in SQLite, variable rendering, a decorator for computed prompts, and a transparent OpenAI SDK wrapper that records every run (prompt version + variables + output + usage).

The basics

from promptkeep import Prompt

prompt = Prompt(
    text="You are a code reviewer. Focus on {var1}.",
    variables={"var1": "correctness"},
    name="REVIEW_SYSTEM",          # the prompt's stable identity
)

prompt.text     # rendered string — safe to pass to any SDK
prompt.raw      # raw template, placeholders intact
prompt.version  # 1 — bumps automatically whenever the template text changes

Same name + edited text ⇒ a new version row in SQLite (deduplicated by content hash). Variables are run data, never versions — change them freely.

Rendering is lenient by default: unknown {placeholders} and JSON braces in the template pass through untouched. Use strict=True (per prompt or via configure) to raise instead.

Computed prompts

from promptkeep import prompt

@prompt(name="REVIEW_SYSTEM")
def review_sys_prompt(var1="some value", n_examples=3):
    examples = "\n".join(load_examples(n_examples))
    return f"You are a reviewer.\n{examples}\nFocus on {{var1}}."

p = review_sys_prompt(var1="security")   # -> Prompt (raw + rendered + version)

The function returns the raw template; the call's arguments become the variables.

OpenAI integration

from openai import OpenAI
from promptkeep import wrap

OpenAI = wrap(OpenAI)                 # or: client = wrap(OpenAI(...))
client = OpenAI()

completion = client.chat.completions.create(
    model="gpt-5.5",
    messages=[
        {"role": "developer", "content": prompt},   # Prompt object, directly
        {"role": "user", "content": "How do I check isinstance?"},
    ],
)

The API receives a plain string; a run is recorded linking this prompt version to the variables used, the rendered text, the model, the output, token usage, and latency. Streaming, async clients, and multi-part content are supported. Tracking failures never break the API call. Unwrapped clients work too — just pass prompt.text.

History

from promptkeep import history

history.versions("REVIEW_SYSTEM")            # lineage, oldest first
print(history.diff("REVIEW_SYSTEM", 1, 3))   # unified diff between versions
history.runs("REVIEW_SYSTEM", version=3)     # recorded runs, newest first

Configuration

import promptkeep

promptkeep.configure(
    db_path="path/to/prompts.db",   # default: ./.promptkeep.db (or $PROMPTKEEP_DB)
    enabled=True,                   # $PROMPTKEEP_DISABLED=1 turns tracking off
    strict=False,                   # raise on missing variables
)

Development

uv sync          # install with dev dependencies
uv run pytest    # run the test suite

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

promptkeep-0.1.0.tar.gz (72.9 kB view details)

Uploaded Source

Built Distribution

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

promptkeep-0.1.0-py3-none-any.whl (23.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: promptkeep-0.1.0.tar.gz
  • Upload date:
  • Size: 72.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for promptkeep-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7da9c80f560a448a35df8db3be2295299dd59c55f4d87bb789ae71b8554099e2
MD5 f3b8741eba2eac139ac36e7a3bd1cf1f
BLAKE2b-256 a87deb31a956faae70d486eed81f00b6d9c0748b786256b2a9d40df4caa32463

See more details on using hashes here.

File details

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

File metadata

  • Download URL: promptkeep-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for promptkeep-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53be5961226e967ff25caed9ce3811f1796dd3d39221d9a69fec1ab581eef51f
MD5 afb3980b8067bbb6b0eb26fb9572cd63
BLAKE2b-256 ca14d8a448837a53e8971389f74798e89a6bfb0add4fb9949738d365f5f64890

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 Sentry Error logging StatusPage Status page