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

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev38.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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.dev38.tar.gz
Algorithm Hash digest
SHA256 ef6b7669b0ac9cfeadf67cdc02802ef3ffed932490acd3551603a00c13cb8582
MD5 02b9e96a23fe6bc8a33d6641b87b1873
BLAKE2b-256 70d9c355b13eb00232fb493c445f40a5d4c24ae65272f4128c78afe4fc06c952

See more details on using hashes here.

File details

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

File metadata

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

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