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.1.0.tar.gz (5.1 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.1.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for promptbind-0.1.0.tar.gz
Algorithm Hash digest
SHA256 36c96da340f061a9d9ed180633682193c2a37064428cf41680ccd3c35d95db4a
MD5 c6fae17737ff9d42a3d85798491f7bfe
BLAKE2b-256 8d061bafb603d6edc417098e33332fb476f5f3e4e30afdbf54aa87f0e02c4652

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptbind-0.1.0.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: promptbind-0.1.0-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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad1246d553e9fe8705e40af32c9e0937cdf28a817cf3bab480f4dd9a25fd7f67
MD5 8c4ecb04b7678d922404170dca2dec2d
BLAKE2b-256 2dadaeadafe1895b9e377fa1a907532b061ea71e325c22bc0a369d40a2844bc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for promptbind-0.1.0-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