Registry / llm-agents / dynamicprompts

dynamicprompts

JSON →
library0.31.0pypypi✓ verified 87d ago

Dynamic Prompts is a Python library designed for creating flexible and expressive prompt templates for text-to-image generators like Stable Diffusion, MidJourney, or Dall-e 2. It enables users to generate a multitude of unique prompts from a single template using features such as variants, wildcards, and combinatorial generation. The library is actively maintained, with its current version being 0.31.0, and receives regular updates.

pip install dynamicprompts
INSTALL
IMPORT
SIG · DYNAMICPROMPTS
D
dynamicprompts
llm-agentspythonv0.31.0
Install
39.4s avg
Import
154ms
Disk
4992MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.31.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
2/4 runs
✓ 43.93s
py 3.11
2/4 runs
✓ 40.18s
py 3.12
2/4 runs
✓ 38.03s
py 3.13
2/4 runs
✓ 35.43s
py 3.9
2/4 runs
2/4 runs
4992MB installed
● package 4992MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RandomPromptGenerator
from dynamicprompts.generators import RandomPromptGenerator
WildcardManager
from dynamicprompts.wildcards import WildcardManager

This quickstart demonstrates how to set up `RandomPromptGenerator` and `WildcardManager` to create dynamic prompts. It uses both inline variants (`{option1|option2}`) and a simple wildcard file (`__colours__`) to show how diverse prompts can be generated from a single template. The `WILDCARD_DIR` is created locally, and a sample wildcard file is generated for immediate execution.

from pathlib import Path from dynamicprompts.wildcards import WildcardManager from dynamicprompts.generators import RandomPromptGenerator # Define a directory for wildcards (optional, create if needed) WILDCARD_DIR = Path("./wildcards") WILDCARD_DIR.mkdir(exist_ok=True) # Create a dummy wildcard file for demonstration (WILDCARD_DIR / "colours.txt").write_text("red\ngreen\nblue") # Initialize WildcardManager and RandomPromptGenerator wm = WildcardManager(WILDCARD_DIR) generator = RandomPromptGenerator(wildcard_manager=wm) # Generate 5 random prompts using a template with a variant and a wildcard template = "A {flower|tree} in __colours__ hue." num_prompts = 5 print(f"Generating {num_prompts} prompts from template: '{template}'") for i, prompt in enumerate(generator.generate(template, num_prompts=num_prompts)): print(f"Prompt {i+1}: {prompt}")
Debug
Known issues
gotchaThe `num_prompts` argument in generator methods (e.g., `generate`) acts as an upper bound, not an exact count. If the number of unique combinations possible in your template is less than `num_prompts`, the generator will yield fewer prompts than requested. This is particularly relevant for combinatorial generation where unique combinations can be limited.
fix
Be aware that the actual number of generated prompts might be less than `num_prompts` if the template's possible variations are exhausted. For precise control over combinatorial generation, consider using `CombinatorialPromptGenerator` and inspecting its `get_template_variants()` method or explicitly setting `max_prompts`.
affects: All versions
gotchaUsing optional features like 'Magic Prompt' can incur a significant initial overhead. The first time a Magic Prompt model is used, it will download a large (approx. 500MB) model file, which can consume time and require substantial VRAM, potentially leading to CUDA errors on systems with limited GPU memory.
fix
Ensure you have sufficient disk space and a stable internet connection for the initial download. If encountering CUDA errors, verify your system meets the VRAM requirements or consider running on a CPU if performance is not critical.
affects: All versions with magicprompt dependency
gotchaSubtle syntax errors in prompt templates (e.g., using `]` instead of `}` for variants, or incorrect wildcard formatting) can lead to parsing failures or unexpected prompt generation behavior. These errors might not be immediately obvious and can manifest as seemingly random crashes or incorrect output after some successful generations.
fix
Carefully review template syntax. The library expects specific delimiters for variants (`{item1|item2}`) and wildcards (`__wildcard__`). Test your templates thoroughly with smaller `num_prompts` counts to catch issues early. Refer to the official syntax guide for details.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dynamicprompts.samplers'
This error typically occurs when attempting to import or use an optional feature (like specific samplers, Magic Prompt, or Attention Grabber) that was not included during the initial `pip install dynamicprompts` command.
fix
Install `dynamicprompts` with its optional dependencies using `pip install "dynamicprompts[magicprompt, attentiongrabber]"` or specifically for the feature you need (e.g., `pip install "dynamicprompts[magicprompt]"`).
Prompting eventually crashes / Prompts stop working after some iterations / Error while generating prompt
Often caused by malformed or syntactically incorrect prompt templates. For example, a missing closing brace `}` or a typo in a wildcard name can lead to the parser failing after some initial successful attempts, especially if the problematic section is not hit immediately.
fix
Inspect your prompt templates for any syntax errors, such as mismatched braces (`{}`), incorrect wildcard delimiters (`__wildcard__`), or invalid variant syntax (`{opt1|opt2}`). Test with a very simple template first to isolate the issue. Check GitHub issues for similar parsing problems.
Upgrade
Version history
0.31.0latest on PyPI · released Mar 21, 2024
Audit
Dependencies
magicpromptoptionalProvides enhanced prompt generation with AI-driven modifiers, typically requiring large model downloads on first use.
attentiongrabberoptionalEmphasizes random phrases in prompts for systems supporting attention syntax, often leveraging libraries like spaCy for NLP.
Agent activity
21 hits · last 30 days
node
18
Bingbot
2
OpenAI (training)
1
Resources
dynamicprompts — pip install dynamicprompts · libregistry