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.dev45.tar.gz.

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev45.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.dev45.tar.gz
Algorithm Hash digest
SHA256 cf34efd851ae3c6cc575d5a6f15f6da9881799896519ae91cd8d37ab5112cac1
MD5 5c40c5a04b4857637a5bc42a768bd1a2
BLAKE2b-256 7b24c41b6b81db639042303c1feeaed8a54cc18d3986820c0b649394287d989a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev45-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","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.dev45-py3-none-any.whl
Algorithm Hash digest
SHA256 f5f45bf25aeac807bfc947ba4658316e3e45fe20c92014acfbf982e4b52a347e
MD5 1ef49629d02520a87fa13a6305e0e178
BLAKE2b-256 b386c36b1cb0f6f9d7404bb95c7118a0e69a5cf0dd726cd8dd3bcaac7b78b8f7

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