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
- Create a prompt file next to your Python module (same name,
.tomlextension):
# example.toml
[greet]
prompt = "Hello, {{ name }}!"
use_jinja2 = true
[farewell]
prompt = "Goodbye."
use_jinja2 = false
- Bind prompts to functions with the decorator. By default the prompt key is the function
__qualname__, but you can override it withkey=....
# 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.
- 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
.tomlfile lives next to each Python file and stores prompt entries. with_promptchecks the TOML at import time, injects the matchingPromptEntry, and routes calls to your function withpromptas the first argument (methods getself/clsfirst, thenprompt).PromptEntry.render(**kwargs)renders with Jinja2 whenuse_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
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 promptbind-0.2.2.tar.gz.
File metadata
- Download URL: promptbind-0.2.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3828b7dfe4a48089bd5643e215b9730318c63fac21e3fd82dd229683988d4c97
|
|
| MD5 |
849fc46b00224b826e89ec0b9afd4371
|
|
| BLAKE2b-256 |
1653ad5ae44e24aa7e275363292fd511184c87c4c95f4054b4550a265f12090f
|
Provenance
The following attestation bundles were made for promptbind-0.2.2.tar.gz:
Publisher:
release.yml on Yikai-Liao/PromptBind
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptbind-0.2.2.tar.gz -
Subject digest:
3828b7dfe4a48089bd5643e215b9730318c63fac21e3fd82dd229683988d4c97 - Sigstore transparency entry: 740470794
- Sigstore integration time:
-
Permalink:
Yikai-Liao/PromptBind@e32894730ec39c51d5a2477c47500117a0da6c6f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Yikai-Liao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e32894730ec39c51d5a2477c47500117a0da6c6f -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file promptbind-0.2.2-py3-none-any.whl.
File metadata
- Download URL: promptbind-0.2.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
180dc758d6453a2ba77c7fd1273ca4bf9065ef39f04137b72f3d48bbde5745c0
|
|
| MD5 |
1ace8924f287fda7a512b49490a12a80
|
|
| BLAKE2b-256 |
97e900890219ab5092eb25b487702fc81a4cb42b4fa8b3ca7c36db0fc92ac745
|
Provenance
The following attestation bundles were made for promptbind-0.2.2-py3-none-any.whl:
Publisher:
release.yml on Yikai-Liao/PromptBind
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
promptbind-0.2.2-py3-none-any.whl -
Subject digest:
180dc758d6453a2ba77c7fd1273ca4bf9065ef39f04137b72f3d48bbde5745c0 - Sigstore transparency entry: 740470808
- Sigstore integration time:
-
Permalink:
Yikai-Liao/PromptBind@e32894730ec39c51d5a2477c47500117a0da6c6f -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Yikai-Liao
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e32894730ec39c51d5a2477c47500117a0da6c6f -
Trigger Event:
workflow_dispatch
-
Statement type: