A lightweight markup language and Python library for writing, composing, and rendering structured LLM prompts.
Project description
MARGARITA
Margarita is a lightweight markup language and Python library for writing, composing, and rendering structured LLM prompts.
Margarita extends Markdown with templating features like variables, conditionals, loops, and includes, making it easy to create dynamic prompts for large language models (LLMs).
| FOR NOW! CLI tool is WIP you will need to download the source and install it locally to use the margarita command. |
Features
- ✨ Framework agnostic — works with any LLM or API
- 🚀 Composable — prompts can be split, reused, and nested
- 🎯 Static-first — templates are validated before execution
- 📦 Metadata — version, and provide metadata alongside your prompts.
Get Started
Here's a Hello World example. helloworld.mg contains the template, and helloworld.json contains the data.
// file:helloworld.mg
Hello, {{name}}!
Welcome to Margarita templating.
// file:helloworld.json
{
"name": "World"
}
Run the following command:
margarita render helloworld.mg
Output:
Hello, World!
Welcome to Margarita templating.
Python Library
Install the package via pip/poetry/uv/etc or whatever package manager you prefer:
pip install margarita
poetry add margarita
uv add margarita
Use the library in your Python code:
from margarita.parser import Parser
from margarita.renderer import Renderer
template = """
You are a helpful assistant.
Task: {{task}}
{% if context %}
Context:
{{context}}
{% endif %}
Please provide a detailed response.
"""
# Parse the template
parser = Parser()
metadata, nodes = parser.parse(template)
# Create a renderer with context
renderer = Renderer(
context={"task": "Summarize the key points", "context": "User is researching AI agents"}
)
# Render the output
prompt = renderer.render(nodes)
print(prompt)
Use the Composer to manage multiple templates:
from margarita.composer import Composer
from pathlib import Path
manager = Composer(Path("./templates"))
# Compose a complex prompt from multiple snippets
prompt = manager.compose_prompt(
snippets=[
"snippets/system_role.mg",
"snippets/task_context.mg",
"snippets/chain_of_thought.mg",
"snippets/output_format.mg"
],
context={
"role": "data scientist",
"user_name": "Bob",
"task": "Analyze customer churn",
"format": "JSON",
"tone": "analytical"
}
)
Documentation
Full documentation is available at https://banyango.mgithub.io/margarita/latest
Development
This project uses uv for dependency management.
Setup Development Environment
uv sync # Install dependencies
Running Tests
# Run tests with pytest
uv run pytest
# Run tests with coverage
uv run pytest --cov=margarita --cov-report=html
Code Quality
# Format code with ruff
uv run ruff format .
# Lint code
uv run ruff check .
# Type checking with mypy
uv run mypy src/margarita
Building the Package
# Build the package
uv build
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Please make sure to:
- Update tests as appropriate
- Follow the existing code style
- Update documentation for any changed functionality
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
- Kyle Reczek - Initial work - Banyango
Acknowledgments
- Markdown
Changelog
See CHANGELOG.md for a history of changes to this project.
Support
If you encounter any problems or have questions, please open an issue.
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 margarita-0.2.0.tar.gz.
File metadata
- Download URL: margarita-0.2.0.tar.gz
- Upload date:
- Size: 718.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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 |
9a107986a7275995d8bf5bbc30f056d2b1012fdf31380f80fd34b592dd01216a
|
|
| MD5 |
6c59a13ea04a8426ad74441be8d35969
|
|
| BLAKE2b-256 |
4b7885a3f5f165f46b4b6c6975bda99e95253802316547a05c5aa716c6803b0b
|
File details
Details for the file margarita-0.2.0-py3-none-any.whl.
File metadata
- Download URL: margarita-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","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 |
220254fe11ca66847b45f2c7a19eea9e1939b6dee090b9eddba67a311bc031a8
|
|
| MD5 |
bd236b575195cd51cd3e5c5ca53967a1
|
|
| BLAKE2b-256 |
11c6b8121e8e4515688a544d4f7c760439d7df2324d1107ccddcd4e6e6729831
|