Skip to main content

🤌 wtprompt: What the Prompt?

wtprompt is a lightweight, no-nonsense library designed to help you manage your LLM prompts efficiently.

Tired of cluttering your code with blocks of text? wtprompt keeps your code clean by loading prompts from files or JSON. Say goodbye to length issues and linting headaches.

🚀 Why wtprompt?

  • ✅ Zero bloat – Need just prompts? No need for a full MLOps library.
  • ✅ Jinja support – Use powerful templating syntax for dynamic prompts.
  • ✅ Markdown-friendly – Ready for OpenAI-style Markdown prompting.
  • ✅ Folder & JSON support – Load prompts from structured files or JSON.
  • ✅ Prompt hashing – Track prompts with unique identifiers.
  • ✅ Built-in preprocessing – Clean input text before inserting it into prompts.

What's New in v0.1.2

  • 🚀 Simplified Prompt Filling: You can now use fill_prompt directly with FolderPrompts:

    base_prompts.fill_prompt('fill_test', {'day': 'Monday', 'this_month': 'August'})
    
  • ⚠ Breaking Change:
    fill_list and PromptGenerator are no longer accessible at the top level (wtprompt).
    Update your imports as follows:

    from wtprompt.fill import fill_list, PromptGenerator
    

    or drop them in favour of the simplified filling method.


🛠 Installation

pip install wtprompt

🔥 Quickstart

1️⃣ Load prompts from a folder

Store your prompts as .txt or .md files in a folder:

prompts/
  ├── fill_test.txt  # "Today is {{ day }} in the month of {{ this_month }}."
  ├── hello.txt
  ├── subfolder/
  │   ├── question.md

Then, load them:

from wtprompt import FolderPrompts

base_prompts = FolderPrompts("prompts")

# Retrieve a prompt
prompt = base_prompts.hello  # Loads "hello.txt"
prompt = base_prompts.subfolder.question  # Loads "subfolder/question.md"

2️⃣ Fill in values

Now you can directly fill prompts using fill_prompt:

filled_prompt = base_prompts.fill_prompt("fill_test", {"day": "Monday", "this_month": "August"})
print(filled_prompt)

➡️ Output:
"Today is Monday in the month of August."

For simpler cases, use fill_list:

filled_prompt = base_prompts.fill_list("fill_test", ["Monday", "August"])

Tip: fill_list is faster for basic substitutions, but Jinja allows more flexibility.


📂 Folder-Based Prompt Management

FolderPrompts helps organize and manage prompts with structured storage.

Load prompts dynamically

my_prompts = FolderPrompts("prompts")

# Direct attribute access
prompt_text = my_prompts.prompt_name
prompt_text = my_prompts.subfolder.prompt_name

Save and load prompt reports

my_prompts.save_prompt_report("report.json")
my_prompts.load_from_prompt_report("report.json", strict=True)

Strict mode ensures that prompt hashes match.


📄 JSON-Based Prompt Loading

Store prompts in a JSON file:

{
    "greeting": "Hello, {{ name }}!",
    "farewell": "Goodbye, {{ name }}."
}

Load and use them:

from wtprompt import JsonPrompts

prompts = JsonPrompts("prompts.json")
prompt = prompts.greeting  # Or prompts("greeting")

Note: JSON loading is not lazy. Use validate=True to check for errors.


📝 Define Prompts in Code

For quick prototyping, define prompts manually:

from wtprompt import PromptLoader

prompts = PromptLoader()
prompts.add_prompt("greeting", "Hello, {{ name }}!")

# Retrieve the prompt and its hash
text, hash_id = prompts.get_prompt("greeting", get_hash=True)

🔧 Text Preprocessing

Raw text can be messy. Use TextPreprocessor for basic cleaning:

from wtprompt.utils.preprocessor import TextPreprocessor

preprocessor = TextPreprocessor()

is_valid, cleaned_text = preprocessor.preprocess("   Hello!   ")
assert is_valid  # True

Customizable settings include:

  • Whitespace handling: Trim spaces, limit consecutive spaces.
  • Validation: Ensure text isn’t empty or gibberish.
  • Truncation: Limit max length.
  • Character filtering: Enforce ASCII, Unicode normalization.

Example:

def build_prompt(prompts, preprocessor, context, question):
    is_ok, context = preprocessor.preprocess(context)
    assert is_ok, "ERROR: Invalid context"
    return base_prompts.fill_list("prompt_name", [context, question])

TL;DR

✔️ Store prompts in folders or JSON.
✔️ Use Jinja templating to insert dynamic values.
✔️ Apply preprocessing for cleaner input.


📜 License & Contributions

Licensed under MIT. Contributions are welcome!

Metadata

Release files for wtprompt 0.1.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 wtprompt 0.1.2
File Size Uploaded
wtprompt-0.1.2.tar.gz 14.9 kB Details

Built distribution (wheel)

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

Total release size: 27.7 kB

Release files / wtprompt-0.1.2.tar.gz

Download URL wtprompt-0.1.2.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
0304f0181016f5f9d4712a94fde19df8e81d0cce412b72d140dd39c8d58d076b
BLAKE2b-256 checksum
How to use checksums
3f12f12a4b9207ae81fb89c2a6c8c6237177c272c67361819be0a7c178b6da2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.14

Release files / wtprompt-0.1.2-py3-none-any.whl

Download URL wtprompt-0.1.2-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d950a31f4e650a2b8853ca3e703081330f90c9c270515ce9f7b6e16ff2bf4af8
BLAKE2b-256 checksum
How to use checksums
f5a0b9a0e9d61dbbdff4495dedb2422bedef9219e41856c39c51c0a0d2b496dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.14

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.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