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

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev44.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.dev44.tar.gz
Algorithm Hash digest
SHA256 bd925500472404e0e8841e155b3a2cf2e73e905f057f0b4939b0d6c8061dc9a8
MD5 3a4f4a0675eb612ee7438de43679d691
BLAKE2b-256 0017ce711c1e6a2659af6a3fcf101a3a5fc746aeab2ce7977489c1080d2654e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev44-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.dev44-py3-none-any.whl
Algorithm Hash digest
SHA256 bd02cc2161f97a5ef2c01dcd05d66775f42f73c59fa5220258f9ebc8e664e703
MD5 8fcb7de70f4958e0f8ab01626f178219
BLAKE2b-256 312cee87410136c3fbb5f7f93fc0ce1e02642761b3fa542b0f922b27f766adc9

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