API Reference¶
This page contains the automatically generated documentation for the DynaPrompt library.
dynaprompt.DynaPrompt(settings_files, environments=True, env=None, validators=None, file_prefix=None, variables=None, auto_render=True, auto_export=False, structure_mode=True)
¶
Lazy-loading prompt configuration manager. Inspired by Dynaconf's LazySettings — zero I/O at instantiation.
Source code in dynaprompt/core.py
prompts
property
¶
Returns all loaded prompts as a dictionary mapping name to PromptNode.
get(name)
¶
using_env(env)
¶
Source code in dynaprompt/core.py
inspect(name=None)
¶
debug_trace(name)
¶
Prints a visual hierarchy of overrides for a specific prompt. Helps trace exactly which environment or file provided which values.
Source code in dynaprompt/core.py
export_to_toml(filepath='pyprompts.toml')
¶
add_validator(*validators)
¶
add_hook(event, name_or_hook, hook=None)
¶
Register hooks. Safe to call before or after first access.
Source code in dynaprompt/core.py
dynaprompt.nodes.PromptNode(name, text, metadata=None, response_schema=None, parent_template=None, history=None, variables=None, validators=None, hooks=None, current_env='default', auto_render=False)
¶
Represents a single parsed prompt. Supports fluent config overrides and Jinja2 rendering with secret injection.
Source code in dynaprompt/nodes.py
render(*args, **kwargs)
¶
Render the prompt template with the provided variables. Runs validators → Jinja2 → after_render hooks.
Source code in dynaprompt/nodes.py
async_render(*args, **kwargs)
async
¶
Asynchronously render the prompt template (I/O non-blocking). Runs validators → Jinja2 async → after_render hooks.
Source code in dynaprompt/nodes.py
rerender(**kwargs)
¶
Alias for render(). Useful for explicitly updating a subset of previously provided variables while retaining the rest.
async_rerender(**kwargs)
async
¶
Async alias for rerender().
Source code in dynaprompt/nodes.py
dynaprompt.nodes.RenderedPrompt(text, config, response_schema=None, source_history=list(), prompt_hash='')
dataclass
¶
dynaprompt.validator.PromptValidator(*names, requires=None, max_tokens=None, response_schema=None, condition=None, when=None, env=None, description=None)
¶
Declarative validator attached to a prompt name.
Usage::
PromptValidator('customer_support',
requires=['user_name', 'issue'],
max_tokens=4096,
env='production',
)
# Composition with & / |
PromptValidator('p1', requires=['a']) & PromptValidator('p2', requires=['b'])
Source code in dynaprompt/validator.py
validate(prompt_node, kwargs, current_env='default')
¶
Raise ValidationError if invalid.