Skip to main content

Python implementation of the AgentMark templatedx transformer

Project description

AgentMark TemplateDX (Python)

Python implementation of the AgentMark templatedx transformer.

Installation

pip install agentmark-templatedx

Usage

This package transforms pre-parsed MDX AST trees. The AST is typically obtained by:

  • Parsing MDX with the TypeScript @agentmark-ai/templatedx package
  • Loading a pre-parsed AST from a JSON file
  • Receiving an AST from the AgentMark runtime
import asyncio
import json
from templatedx import TemplateDX

async def main():
    engine = TemplateDX()

    # Load a pre-parsed MDX AST (from TypeScript parser or JSON file)
    with open("template.ast.json") as f:
        ast = json.load(f)

    # Transform the AST with props
    result = await engine.transform(
        ast,
        props={"name": "Alice", "items": [1, 2, 3]}
    )

    print(result)

asyncio.run(main())

Custom Plugins

from templatedx import TagPlugin, PluginContext

class MyPlugin(TagPlugin):
    async def transform(self, props, children, context):
        # Transform children and return result
        transformer = context.create_node_transformer(context.scope)
        return await transformer.transform_children(children)

engine = TemplateDX()
engine.register_tag_plugin(MyPlugin(), ["MyTag"])

Custom Filters

engine = TemplateDX()
engine.register_filter("double", lambda x: x * 2)

Built-in Filters

  • capitalize(str) - Capitalize first character
  • upper(str) - Uppercase string
  • lower(str) - Lowercase string
  • truncate(str, length) - Truncate with ellipsis
  • abs(num) - Absolute value
  • join(arr, separator) - Join array elements
  • round(num, decimals) - Round number
  • replace(str, search, replacement) - Replace occurrences
  • urlencode(str) - URL encode string
  • dump(any) - JSON stringify

Built-in Tags

  • <If condition={...}> / <ElseIf condition={...}> / <Else> - Conditional rendering
  • <ForEach arr={...}>{(item, index) => ...}</ForEach> - Array iteration
  • <Raw>...</Raw> - Raw content passthrough

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

agentmark_templatedx-0.2.0.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

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

agentmark_templatedx-0.2.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file agentmark_templatedx-0.2.0.tar.gz.

File metadata

  • Download URL: agentmark_templatedx-0.2.0.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for agentmark_templatedx-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ad449fdaeb2099e8547bb37f2de6a83eff8bca35a94b1a604117b74e0a4e8e09
MD5 87153d4dc9f2a37d21352949681d874c
BLAKE2b-256 4e640538786bd757ddb7b2a48c939f3ce2ef7cc6e7cc949141760b57c1e68814

See more details on using hashes here.

File details

Details for the file agentmark_templatedx-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for agentmark_templatedx-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44ba8cc3663d8b66c4cff6ee0f40c7828bd36d41edf11ad7bfc48231eb85a5f7
MD5 bbbf4da255e3475530d53a60f4234268
BLAKE2b-256 418c701e5fa7d5ffac4d7a81fcad95c256da8fd178afe66e5595c977b3b23326

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