Follow @_johnwheeler for updates
Flask-Ask is a Flask extension that makes building Alexa skills for the Amazon Echo easier and much more fun.
Get started with the Flask-Ask quickstart on Amazon's Developer Blog.
👊 Level Up with our Alexa Skills Kit Video Tutorial and chat on Gitter.im
A Flask-Ask application looks like this:
from flask import Flask
from flask_ask import Ask, statement
app = Flask(__name__)
ask = Ask(app, '/')
@ask.intent('HelloIntent')
def hello(firstname):
speech_text = "Hello %s" % firstname
return statement(speech_text).simple_card('Hello', speech_text)
if __name__ == '__main__':
app.run()
In the code above:
- The
Ask
object is created by passing in the Flask application and a route to forward Alexa requests to. - The
intent
decorator mapsHelloIntent
to a view functionhello
. - The intent's
firstname
slot is implicitly mapped tohello
'sfirstname
parameter. - Lastly, a builder constructs a spoken response and displays a contextual card in the Alexa smartphone/tablet app.
More code examples are in the samples directory.
Since Alexa responses are usually short phrases, you might find it convenient to put them in the same file. Flask-Ask has a Jinja template loader that loads multiple templates from a single YAML file. For example, here's a template that supports the minimal voice interface above:
hello: Hello, {{ firstname }}
Templates are stored in a file called templates.yaml located in the application root. Checkout the Tidepooler example to see why it makes sense to extract speech out of the code and into templates as the number of spoken phrases grow.
Flask-Ask handles the boilerplate, so you can focus on writing clean code. Flask-Ask:
- Has decorators to map Alexa requests and intent slots to view functions
- Helps construct ask and tell responses, reprompts and cards
- Makes session management easy
- Allows for the separation of code and speech through Jinja templates
- Verifies Alexa request signatures
To install Flask-Ask:
pip install flask-ask
These resources will get you up and running quickly:
Fantastic 3-part tutorial series by Harrison Kinsley
- Intro and Skill Logic - Alexa Skills w/ Python and Flask-Ask Part 1
- Headlines Function - Alexa Skills w/ Python and Flask-Ask Part 2
- Testing our Skill - Alexa Skills w/ Python and Flask-Ask Part 3
You can deploy using any WSGI compliant framework (uWSGI, Gunicorn). If you haven't deployed a Flask app to production, checkout flask-live-starter.
To deploy on AWS Lambda, use Zappa.
Note: When deploying to AWS Lambda with Zappa, make sure you point the Alexa skill to the HTTPS API gateway that Zappa creates.
Thanks for checking this library out! I hope you find it useful.
Of course, there's always room for improvement. Feel free to open an issue so we can make Flask-Ask better.
Special thanks to @kennethreitz for his sense of style, and of course, @mitsuhiko for Flask