Skip to main content

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.

Metadata

Release files for promptbind 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for promptbind 0.2.2
File Size Uploaded
promptbind-0.2.2.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for promptbind 0.2.2
File Interpreter ABI Platform
promptbind-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 23.3 kB

Release files / promptbind-0.2.2.tar.gz

Download URL promptbind-0.2.2.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3828b7dfe4a48089bd5643e215b9730318c63fac21e3fd82dd229683988d4c97
BLAKE2b-256 checksum
How to use checksums
1653ad5ae44e24aa7e275363292fd511184c87c4c95f4054b4550a265f12090f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.

Transparency log

Release files / promptbind-0.2.2-py3-none-any.whl

Download URL promptbind-0.2.2-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
180dc758d6453a2ba77c7fd1273ca4bf9065ef39f04137b72f3d48bbde5745c0
BLAKE2b-256 checksum
How to use checksums
97e900890219ab5092eb25b487702fc81a4cb42b4fa8b3ca7c36db0fc92ac745
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 4, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page