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

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev47.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.dev47.tar.gz
Algorithm Hash digest
SHA256 1514d0d771f49940937603abe1977af49ed939e86a3efcca4a86cf88311933e6
MD5 48cb5970bd2bfa1e98f64c79f61e9715
BLAKE2b-256 9752b069a44c67da389b8cd2765725c5d4dd8b37f22ffef14385c1d3d2a529e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: swarmauri_prompt_j2prompttemplate-0.9.0.dev47-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.dev47-py3-none-any.whl
Algorithm Hash digest
SHA256 45c2642fc74bbd0579f43b79a71f83f00f2a05d9d92b35f57927b7b502586533
MD5 ff106aa9c87ae84281064da101da0825
BLAKE2b-256 787511c280fcd99fcea88fd666e332047755e525f9576a699ccfe69e3da80bf9

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