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/templatedxpackage - 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 characterupper(str)- Uppercase stringlower(str)- Lowercase stringtruncate(str, length)- Truncate with ellipsisabs(num)- Absolute valuejoin(arr, separator)- Join array elementsround(num, decimals)- Round numberreplace(str, search, replacement)- Replace occurrencesurlencode(str)- URL encode stringdump(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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentmark_templatedx-0.1.1.tar.gz.
File metadata
- Download URL: agentmark_templatedx-0.1.1.tar.gz
- Upload date:
- Size: 24.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
309ac4aae1bf17c5890dc49aaad8eebb919525bca297a1fe976d0f40c79e8aa9
|
|
| MD5 |
5d5bb8036ea3143da8b9be1409a209d3
|
|
| BLAKE2b-256 |
2477a309e5708162b3873b80d0c9c6ade0d6d5a38880d742db9770b5ba355131
|
File details
Details for the file agentmark_templatedx-0.1.1-py3-none-any.whl.
File metadata
- Download URL: agentmark_templatedx-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d8eca87067076e985b9e56ec306bca4c9f19874c21b9d3edcd7be13ff180c4f
|
|
| MD5 |
1e3b93a8d0cf060635703ddd2d2fe102
|
|
| BLAKE2b-256 |
058cf2446f6b9026c94bdfbec38ad897cf6cc46bc4ba3f9f4a18ce36a75d1cea
|