Skip to main content

A lightweight, no-nonsense library for managing your LLM prompts.

Project description

🤌 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!

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

wtprompt-0.1.2.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

wtprompt-0.1.2-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file wtprompt-0.1.2.tar.gz.

File metadata

  • Download URL: wtprompt-0.1.2.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for wtprompt-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0304f0181016f5f9d4712a94fde19df8e81d0cce412b72d140dd39c8d58d076b
MD5 188962d05e662cfa7d8f3dd03befdafa
BLAKE2b-256 3f12f12a4b9207ae81fb89c2a6c8c6237177c272c67361819be0a7c178b6da2f

See more details on using hashes here.

File details

Details for the file wtprompt-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: wtprompt-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.14

File hashes

Hashes for wtprompt-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d950a31f4e650a2b8853ca3e703081330f90c9c270515ce9f7b6e16ff2bf4af8
MD5 5dd46e24f46269d8e971cbe464ff530d
BLAKE2b-256 f5a0b9a0e9d61dbbdff4495dedb2422bedef9219e41856c39c51c0a0d2b496dd

See more details on using hashes here.

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