Skip to main content

ASK SDK Jinja Renderer

ask-sdk-jinja-renderer is an SDK package for supporting template responses for skill developers, when built using ASK Python SDK. It provides jinja framework as a template renderer to render the response loaded from the template and inject the data passed and finally deserialize to custom response format.

Quick Start

If you already have a skill built using the ASK SDK builders, then you only need to do the following, to start using template resolvers to generate responses.

  • Import FileSystemTemplateLoader from ask_sdk_core and JinjaTemplateRenderer from ask_sdk_jinja_renderer packages.

  • Register the Loaders with appropriate parameters and also a Renderer into skill builder using add_loaders and add_renderer methods.

  • Create a template file as shown below and provide the path of the directory and its encoding scheme as parameters while initializing the loader.

example_app/my_skill.py

from ask_sdk_core.skill_builder import SkillBuilder
from ask_sdk_core.handler_input import HandlerInput
from ask_sdk_core.dispatch_components import AbstractRequestHandler
from ask_sdk_core.utils import is_request_type
from ask_sdk_core.view_resolvers import FileSystemTemplateLoader
from ask_sdk_jinja_renderer import JinjaTemplateRenderer
from ask_sdk_model import Response

sb = SkillBuilder()

class LaunchRequestHandler(AbstractRequestHandler):
    """Handler for skill launch."""
    def can_handle(self, handler_input):
        # type: (HandlerInput) -> bool
        return is_request_type("LaunchRequest")(handler_input)

    def handle(self, handler_input):
        # type: (HandlerInput) -> Response
        speech_text = "Hello!!"

        template_name = "responses"

        data_map = {
            'speech_text': speech_text,
            'card': {
                'type': 'Simple',
                'title': 'Jinja2 Template',
                'content': speech_text
            },
            'should_end_session': 'false'
        }

        return handler_input.generate_template_response(template_name, data_map, file_ext='jinja')

# Other skill components here ....

# Register all handlers, loaders, renderers, interceptors etc.
sb.add_request_handler(LaunchRequestHandler())
# Add default file system loader on skill builder
sb.add_loader(FileSystemTemplateLoader(dir_path="templates", encoding='utf-8'))
# Add default jinja renderer on skill builder
sb.add_renderer(JinjaTemplateRenderer())


skill = sb.create()

example_app/templates/responses.jinja

{
    "outputSpeech": {
        "type": "SSML",
        "ssml": "<speak>{{ speech_text }}</speak>"
    },
    "card": {
        "type": "{{ card.type }}",
        "title": "{{ card.title}}",
        "content": "{{ card.content }}"
    },
    "shouldEndSession": "{{ should_end_session }}"
}

Installation

Assuming that you have Python and virtualenv installed, you can install the package from PyPi as follows:

$ virtualenv venv
$ . venv/bin/activate
$ pip install ask-sdk-jinja-renderer

Usage and Getting Started

Getting started guides, SDK Features, API references, samples etc. can be found at Read The Docs

Got Feedback?

  • We would like to hear about your bugs, feature requests, questions or quick feedback. Please search for the existing issues before opening a new one. It would also be helpful if you follow the templates for issue and pull request creation. Please follow the contributing guidelines!!

  • Request and vote for Alexa features!

CHANGELOG

1.0

  • Initial release of Ask SDK Python Jinja Renderer Package.

Metadata

Release files for ask-sdk-jinja-renderer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ask-sdk-jinja-renderer 1.0.0
File Size Uploaded
ask-sdk-jinja-renderer-1.0.0.tar.gz 5.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ask-sdk-jinja-renderer 1.0.0
File Interpreter ABI Platform
ask_sdk_jinja_renderer-1.0.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 11.6 kB

Release files / ask-sdk-jinja-renderer-1.0.0.tar.gz

Download URL ask-sdk-jinja-renderer-1.0.0.tar.gz
Size 5.3 kB
Tags Source
SHA-256 checksum
How to use checksums
63df2759955f777807720c5635338ce2f2fb0b7b7f8102530731e23b8c7c72ec
BLAKE2b-256 checksum
How to use checksums
a17bd23622bd4cc2e5c7210efaca681a352cd323e57d8f32dfa9af56aadbc3cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.3

Release files / ask_sdk_jinja_renderer-1.0.0-py2.py3-none-any.whl

Download URL ask_sdk_jinja_renderer-1.0.0-py2.py3-none-any.whl
Size 6.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ddb17b7cb39ea7d26e8ee48cd2111195f68c63daabb78853d81ca0385069e4a6
BLAKE2b-256 checksum
How to use checksums
baf28051fc0cd20661fc193700fcb49247f99cb40c9771acc7b806ca9a4e0b48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.34.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page