Skip to main content

Add your description here

Project description

PromptBind

PromptBind lets you bind prompts to functions and methods with a small decorator and TOML sidecar files. It keeps prompts close to your code, supports optional Jinja2 rendering, and allows hot-swapping prompt keys at runtime.

Installation

pip install promptbind

QuickStart

  1. Create a prompt file next to your Python module (same name, .toml extension):
# example.toml
[greet]
prompt = "Hello, {{ name }}!"
use_jinja2 = true

[farewell]
prompt = "Goodbye."
use_jinja2 = false
  1. Bind prompts to functions with the decorator. By default the prompt key is the function __qualname__, but you can override it with key=....
# example.py
from promptbind import with_prompt, PromptEntry

@with_prompt()
def greet(prompt: PromptEntry) -> str:
    return prompt.render(name="Ada")

@with_prompt(key="farewell")
def bye(prompt: PromptEntry) -> str:
    return prompt.render()

if __name__ == "__main__":
    print(greet())  # -> Hello, Ada!
    print(bye())    # -> Goodbye.
  1. Patch prompt keys at runtime if you want to swap to another entry in the same TOML file:
from promptbind import set_prompt_key_patch, unset_prompt_key_patch

set_prompt_key_patch(greet, "farewell")  # greet now uses the farewell prompt
print(greet())  # -> Goodbye.
unset_prompt_key_patch(greet)            # revert to original key

How it works

  • A .toml file lives next to each Python file and stores prompt entries.
  • with_prompt checks the TOML at import time, injects the matching PromptEntry, and routes calls to your function with prompt as the first argument (methods get self/cls first, then prompt).
  • PromptEntry.render(**kwargs) renders with Jinja2 when use_jinja2 = true; otherwise it returns the raw string (passing kwargs in that case is a no-op).

Thread safety note

set_prompt_key_patch/unset_prompt_key_patch mutate shared process-wide state. Avoid calling them concurrently across threads, or you may observe races where a call picks up the wrong prompt key. If you must patch in a multithreaded context, guard these calls with your own locking.

Minimal project layout

project/
├─ example.py
└─ example.toml

That is all you need to start binding prompts to your code. See test/example.py and test/example.toml in the repo for a runnable sample.

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

promptbind-0.2.1.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

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

promptbind-0.2.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file promptbind-0.2.1.tar.gz.

File metadata

  • Download URL: promptbind-0.2.1.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptbind-0.2.1.tar.gz
Algorithm Hash digest
SHA256 5b7b82249a491553f599e3813218f72de93a632c3c48a67993c1d462449a5490
MD5 2e923d98287dd7fc0c7028efcfda2925
BLAKE2b-256 c7ba4e87f34fd04ad18ce47737f4942d1ea14b3ee79ab441ac2358e59f3f46db

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptbind-0.2.1.tar.gz:

Publisher: release.yml on Yikai-Liao/PromptBind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file promptbind-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: promptbind-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for promptbind-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c3219a6e36e67a684525e09c36f62a839e12f794c62a3c05ddd7119a8aa162b3
MD5 607fa174449d63d4dfa22a037785b573
BLAKE2b-256 0f2dc5e762e02136d845dc7f39471da9e0a3feb3dd7cc717b359ae224306d1f1

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptbind-0.2.1-py3-none-any.whl:

Publisher: release.yml on Yikai-Liao/PromptBind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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