A powerful, lazy-loading prompt configuration manager.
Project description
dynaprompt - Lazy-loading prompt configuration manager built directly on Dynaconf's principles.
DynaPrompt is a powerful, lazy-loading prompt configuration manager inspired by Dynaconf. It offers a structured way to manage, version, and render LLM prompts while separating prompt text from configuration metadata.
🚀 30-Second Quickstart
pip install dynaprompt
- Create a
prompts.toml:
[default.greeting]
template = "Hello {{ name }}! You are a helpful assistant."
[production.greeting]
template = "Hello {{ name }}! You are a professional consultant."
- Use it in Python:
from dynaprompt import DynaPrompt
prompts = DynaPrompt(settings_files=["prompts.toml"])
# Renders: "Hello Emam! You are a helpful assistant."
print(prompts.greeting.render(name="Emam").text)
💡 Why DynaPrompt?
1. Lazy Loading is the Core
Most libraries load prompts at import time. This makes environment swapping hard and slows down startup.
The "Old" Way (Hardcoded/Manual):
# Loaded once, forever. Hard to swap for tests/production.
SYSTEM_PROMPT = open("prompts/system.txt").read()
The DynaPrompt Way:
from dynaprompt import prompts
# File is only read NOW. Respects ENV_FOR_DYNAPROMPT=production automatically.
print(prompts.system.render())
2. Why not just use Dynaconf?
Since Dynaconf handles strings, why a new library? DynaPrompt adds prompt-specific logic:
- Jinja2 First-Class: Automatic variable injection, recursive flattening, and secret resolution.
- Schema Auto-loading: Automatically registers Pydantic models from
.pyfiles as response schemas. - Prompt Inheritance: Use
extendsto share model config (temperature, max_tokens) between templates. - Render State: Remembers previous variables for precise partial updates via
.rerender().
3. Comparison with others
| Feature | DynaPrompt | Prompt-Poet / Promptix | f-strings |
|---|---|---|---|
| Boilerplate | Zero (just a folder) | Medium (manual registration) | High |
| Lazy Loading | ✅ Yes | ❌ No | ❌ No |
| Env Layers | ✅ Native | ⚠️ Manual | ❌ No |
| Inheritance | ✅ Native | ❌ No | ❌ No |
| Schemas | ✅ Auto-discovery | ⚠️ Manual | ❌ No |
✨ Features
- File-based Prompt Management: Write prompt templates in clean Markdown (
.mdor.txt) with YAML frontmatter, or group multiple prompts in aprompts.tomlfile. - Auto-Discovery & Companion Files: Pass a directory like
settings_files=["prompts/"]and DynaPrompt automatically loads all.mdfiles. It also auto-discovers a siblingprompts.tomlfor managing metadata separately. - Automatic Name Sanitization: Filenames like
Call Analysis.mdbecomeprompts.call_analysis. - Validation & Hooks: Enforce constraints on rendered prompts and intercept rendering with a powerful hook system.
🛠 Usage
Loading from a Directory & Namespaces
DynaPrompt excels at organizing templates as files. When you load files from a nested directory structure (e.g., examples/google/gemini.md), it automatically builds a nested namespace.
from dynaprompt import DynaPrompt
prompts = DynaPrompt(
settings_files=["examples/"], # Scans for .md, .toml, .py schemas recursively
environments=True
)
# Accessing a nested prompt using intuitive dot notation:
rendered = prompts.google.gemini.render(user_name="Emam", text="DynaPrompt is great!")
print(rendered.text)
print(rendered.config["model"]) # "gemini-1.5-pro" (from frontmatter or .toml)
# Partial update: keeps "user_name" but changes "text"
updated = prompts.google.gemini.rerender(text="It's really fast.")
Auto-Exporting Prompts to TOML
You can automatically export your entire loaded prompt structure into a central pyprompts.toml file. This acts as an interface for users to easily view or override prompt templates and settings.
# Pass auto_export=True, or auto_export="custom_path.toml"
prompts = DynaPrompt(settings_files=["examples/"], auto_export=True)
# Access a prompt to trigger the lazy load and export the file
_ = prompts.google.gemini
File-Based Templates and Variables
Instead of writing long strings in your configuration files, you can reference external files directly in your TOML config. DynaPrompt will automatically resolve and load their contents!
[default.my_prompt]
# Read the prompt text directly from a file
template = "path/to/external_template.md"
# Load default variables from a JSON or YAML file
variables = "path/to/default_vars.json"
You can also define prompt-specific variables directly inline:
[default.my_prompt]
template = "Hello {{ username }}! Your tier is {{ tier }}."
[default.my_prompt.variables]
tier = "Premium"
Schema Integration
DynaPrompt automatically registers Pydantic models found in your settings_files.
# If examples/schemas.py defines class UserProfile(BaseModel):
prompts = DynaPrompt(settings_files=["examples/"])
# Model is available as an attribute
user_schema = prompts.UserProfile
# Use it in rendering (automatically injects JSON schema if referenced in template)
rendered = prompts.fetch_user.render(username="em2m")
🔍 Inspection & Tab-Completion
DynaPrompt is designed for developer productivity.
- Tab-Completion: Use
dir(prompts)or hitTabin your IDE to see all available prompts and schemas. - History Tracking: Inspect exactly where a prompt was loaded from and how it was merged across layers.
# See loading history for a prompt
print(prompts.inspect("customer_support"))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dynaprompt-0.1.3.tar.gz.
File metadata
- Download URL: dynaprompt-0.1.3.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb792df2ca683247772e8c683ddd720fdc22648ad2af0e77661b5a645c1931f0
|
|
| MD5 |
585e6d045091ac7b50cbffe53d6acd7e
|
|
| BLAKE2b-256 |
93b4e6a4a70019a395a24a545789fe8fd5b246755d81284590c71ef0cf3cf8cd
|
File details
Details for the file dynaprompt-0.1.3-py3-none-any.whl.
File metadata
- Download URL: dynaprompt-0.1.3-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.11 {"installer":{"name":"uv","version":"0.11.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79fd0dc6e23fec2e5a014643c75b60fbc1b9a80b28a0cf5b961c742c478ccc72
|
|
| MD5 |
b9ae7715d84ad0a1ecd65b5be9eb6f72
|
|
| BLAKE2b-256 |
3887783d34b62385f1ee13f7973188a4bead223deb7d0119783c338edf7fd689
|