This library largely implements the JSON-to-JSON Adaptive Cards Template language for Python. It allows you to dynamically expand Adaptive Card templates using data and host-specific information.
- Supports most standard features of the Adaptive Cards Template language.
- Inline data expansion with
$data. - Conditional rendering with
$when. - Expression evaluation using
${}syntax. - Custom functions like
if()andjson(). - Supports
$root,$host, and$indexfor advanced templating.
- Adaptive expressions prebuilt functions.
To install the package, use:
pip install adaptive-cards-templating-pyHere's a quick example of how to use the library:
import json
from adaptive_cards_templating_py import Template
# Define a template
template_json = {
"type": "AdaptiveCard",
"body": [
{
"type": "TextBlock",
"text": "${message}"
}
]
}
# Create a Template instance
template = Template(template_json)
# Expand the template with data
data = {
"$root": {
"message": "Hello, Adaptive Cards!"
}
}
card = template.expand(data)
# Pretty-print the card
print(json.dumps(card, indent=2))Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Write tests for your changes.
- Commit your changes and push the branch.
- Open a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.