A Python package for managing prompts using Jinja2 templates
Project description
Promptly
A simple Python library for managing prompts using Jinja2 templates with YAML frontmatter support.
Build
Installation
pip install promptly-ai
Usage
Basic Usage
Create a prompt file with YAML frontmatter:
---
title: Greeting Prompt
description: A simple greeting prompt
tags: [greeting, basic]
---
Hello, {{ name }}! How are you today?
Then use it in your Python code:
from promptly_ai import PromptManager
# Simple rendering
content = PromptManager.render("greeting.txt", name="World")
print(content) # "Hello, World! How are you today?"
# Get metadata
metadata = PromptManager.get_metadata("greeting.txt")
print(metadata["title"]) # "Greeting Prompt"
print(metadata["description"]) # "A simple greeting prompt"
# Get both content and metadata
content, metadata = PromptManager.render_with_metadata("greeting.txt", name="World")
Prompt Formats
XML Format
---
version: 1.0.0
model: gpt-4
---
<system>
<role>You are a helpful assistant.</role>
<context>The current time is {{ time }}.</context>
<instructions>
<item>Be helpful</item>
<item>Be concise</item>
<item>Be accurate</item>
</instructions>
</system>
Markdown Format
---
version: 1.0.0
model: gpt-4
---
# System Prompt
You are a helpful assistant.
## Context
The current time is {{ time }}.
## Instructions
1. Be helpful
2. Be concise
3. Be accurate
Mixed Format
---
version: 1.0.0
model: gpt-4
---
<system>
# Role
You are a helpful assistant.
## Context
The current time is {{ time }}.
## Instructions
1. Be helpful
2. Be concise
3. Be accurate
</system>
Metadata Support
Prompts can include metadata in YAML frontmatter. Common metadata fields include:
---
version: 1.0.0
author: Your Name
description: A description of the prompt
model: gpt-4
---
Your prompt content here
You can access metadata using convenience methods:
from promptly_ai import PromptManager
# Get specific metadata fields
version = PromptManager.get_version("prompt.txt")
author = PromptManager.get_author("prompt.txt")
description = PromptManager.get_description("prompt.txt")
model = PromptManager.get_model("prompt.txt")
# Or get all metadata
metadata = PromptManager.get_metadata("prompt.txt")
Advanced Usage
You can use any Jinja2 template features in your prompts:
---
title: Story Generator
description: Generate a story based on parameters
parameters:
genre: [fantasy, sci-fi, mystery]
length: [short, medium, long]
---
Write a {{ parameters.genre }} story that is {{ parameters.length }} in length.
{% if parameters.genre == "fantasy" %}
Include magical elements and mythical creatures.
{% elif parameters.genre == "sci-fi" %}
Include futuristic technology and space exploration.
{% else %}
Include suspense and plot twists.
{% endif %}
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 promptly_ai-0.2.0.tar.gz.
File metadata
- Download URL: promptly_ai-0.2.0.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0870666f6f136567433d60c3e886ba966aea29a847283ad76e815c8978d0c18
|
|
| MD5 |
de02df0d977b84b822473e4b14376b2b
|
|
| BLAKE2b-256 |
b3ba9b89520cbd99cf9082a5495ecdf1831adb831902907d3f005a8bf0ffc271
|
File details
Details for the file promptly_ai-0.2.0-py3-none-any.whl.
File metadata
- Download URL: promptly_ai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79e9fe4ed8f740720ab9552b98d51fd559ac6424da512b6e563646f83213c6db
|
|
| MD5 |
63162f4952d65a326dd0be385f281883
|
|
| BLAKE2b-256 |
05744a1ff988e25a0fc5e64c45288b20ad0fd907d71e6cbecf275567b676be7d
|