Skip to main content

Jinja2 Prompt Template for Swarmauri.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_prompt_j2prompttemplate


Swarmauri Prompt J2PromptTemplate

J2PromptTemplate is the Swarmauri Jinja2 prompt template implementation. It accepts literal template strings or template files, renders them with the variables you provide, and registers itself as the J2PromptTemplate swarmauri.prompts entry point.

Highlights

  • Load template content from inline strings or filesystem paths.
  • Configure one or more search directories via templates_dir for reusable Jinja2 templates with fallback lookup.
  • Ship with helpful filters (split, make_singular, make_plural) for prompt engineering tasks.
  • Call the instance directly (template({...})) or use generate_prompt() to render with the stored variables.

Installation

Choose the tool that matches your workflow:

# pip
pip install swarmauri_prompt_j2prompttemplate

# Poetry
poetry add swarmauri_prompt_j2prompttemplate

# uv
uv add swarmauri_prompt_j2prompttemplate

Usage

Render a template string

from swarmauri_prompt_j2prompttemplate import J2PromptTemplate

template = J2PromptTemplate(template="Hello, {{ name }}!")
result = template({"name": "World"})
print(result)  # Hello, World!

Load templates from disk (with filters and search paths)

from pathlib import Path

from swarmauri_prompt_j2prompttemplate import J2PromptTemplate

templates_dir = Path("templates")
templates_dir.mkdir(parents=True, exist_ok=True)

template_path = templates_dir / "greeting.j2"
template_path.write_text("Hello, {{ animal|make_plural }}!", encoding="utf-8")

prompt = J2PromptTemplate(templates_dir=str(templates_dir))
prompt.set_template(template_path)

print(prompt({"animal": "fox"}))  # Hello, foxes!

set_template() loads the file with the configured environment. The template file is located relative to the provided templates_dir. If the loader cannot find it immediately, the class searches recursively before falling back to the template's own directory.

Want to help?

If you want to contribute to swarmauri-sdk, read up on our guidelines for contributing that will help you get started.

Project details


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

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file swarmauri_prompt_j2prompttemplate-0.9.0.dev34.tar.gz.

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev34.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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

Hashes for swarmauri_prompt_j2prompttemplate-0.9.0.dev34.tar.gz
Algorithm Hash digest
SHA256 8b769e2af4d697427ee735e9a2ea84cc8405cc2bd6ffdd19e1cbe98b2fc77283
MD5 b95c89f6c3762f92058846d435934d33
BLAKE2b-256 9f3ff6139b16d55a744ae595e7d8cf09a39b13f1e3039a4999fc8dd416cccd97

See more details on using hashes here.

File details

Details for the file swarmauri_prompt_j2prompttemplate-0.9.0.dev34-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev34-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.3 {"installer":{"name":"uv","version":"0.10.3","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

Hashes for swarmauri_prompt_j2prompttemplate-0.9.0.dev34-py3-none-any.whl
Algorithm Hash digest
SHA256 b1334cc0c6056fe30f6b51983979f5125ea17ac7c0804a33de524426dd1ff6a2
MD5 742022e80e7e78cb246802024844e5c5
BLAKE2b-256 0889ab62a533a4cd1d8a2036a895bc9b730f74908d0214c2905a48d49aa8e7fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page