Package: django-alexa
Amazon Alexa Skills Kit integration for DjangoThe django-alexa framework leverages the django-rest-framework package to support
the REST API that alexa skills need to use, but wraps up the bolierplate for intent
routing and response creation that you’d need to write yourself.Freeing you up to just write your alexa intents and utterances.QuickstartFeeling impatient? I like your style.$pipinstalldjango-alexaIn your django settings.py add the following:INSTALLED_APPS=['django_alexa','rest_framework',# don't forget to add this too...]In your django urls.py add the following:urlpatterns=[url(r'^',include('django_alexa.urls')),...]Your django app will now have a new REST api endpoint at/alexa/ask/that will handle all the incoming request and route them to the intents defined
in any “alexa.py” file.Set environment variables to configure the validation needs:ALEXA_APP_ID_DEFAULT="Your Amazon Alexa App ID DEFAULT"ALEXA_APP_ID_OTHER="Your Amazon Alexa App ID OTHER"# for each appALEXA_REQUEST_VERIFICATON=True# Enables/Disable request verificationYou can service multiple alexa skills by organizing your intents by an app name.
See the intent decorator’s “app” argument for more information.If you set your django project to DEBUG=True django-alexa will also do some
helpful debugging for you during request ingestion, such as catch all exceptions
and give you back a stacktrace and error type in the alexa phone app.django-alexa is also configured to log useful information such as request body,
request headers, validation as well as response data, this is all configured
through the standard python logging setup using the logger ‘django-alexa’In your django project make analexa.pyfile.
This file is where you define all your alexa intents and utterances.
Each intent must return a valid alexa response dictionary.  To aid in this the
django-alexa api provides a helper class calledResponseBuilder.
This class has a function to speed up building these dictionaries for responses.Please see the documentation on the class for a summary of the details or head
tohttps://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interface-referenceand checkout the more verbose documentation on proper alexa responsesExample:fromdjango_alexa.apiimportfields,intent,ResponseBuilderHOUSES=("gryffindor","hufflepuff","ravenclaw","slytherin")@intentdefLaunchRequest(session):"""
    Hogwarts is a go
    ---
    launch
    start
    run
    begin
    open
    """returnResponseBuilder.create_response(message="Welcome to Hog warts school of witchcraft and wizardry!",reprompt="What house would you like to give points to?",end_session=False,launched=True)classPointsForHouseSlots(fields.AmazonSlots):house=fields.AmazonCustom(label="HOUSE_LIST",choices=HOUSES)points=fields.AmazonNumber()@intent(slots=PointsForHouseSlots)defAddPointsToHouse(session,house,points):"""
    Direct response to add points to a house
    ---
    {points} {house}
    {points} points {house}
    add {points} points to {house}
    give {points} points to {house}
    """kwargs={}kwargs['message']="{0}points added to house{1}.".format(points,house)ifsession.get('launched'):kwargs['reprompt']="What house would you like to give points to?"kwargs['end_session']=Falsekwargs['launched']=session['launched']returnResponseBuilder.create_response(**kwargs)The django-alexa framework also provides two django management commands that
will build your intents and utterances schema for you by inspecting the code.
The django-alexa framework also defines some best practice intents to help
get you up and running even faster, but allows you to easily override them,
as seen above with the custom LaunchRequest.>>>pythonmanage.pyalexa_intents{"intents":[{"intent":"StopIntent","slots":[]},{"intent":"PointsForHouse","slots":[{"name":"points","type":"AMAZON.NUMBER"},{"name":"house","type":"HOUSE_LIST"}]},{"intent":"HelpIntent","slots":[]},{"intent":"LaunchRequest","slots":[]},{"intent":"SessionEndedRequest","slots":[]},{"intent":"UnforgivableCurses","slots":[]},{"intent":"CancelIntent","slots":[]}]}>>>pythonmanage.pyalexa_utterancesStopIntentstopStopIntentendHelpIntenthelpHelpIntentinfoHelpIntentinformationLaunchRequestlaunchLaunchRequeststartLaunchRequestrunLaunchRequestbeginLaunchRequestopenPointsForHouse{points}{house}PointsForHouse{points}points{house}PointsForHouseadd{points}pointsto{house}PointsForHousegive{points}pointsto{house}SessionEndedRequestquitSessionEndedRequestnevermindCancelIntentcancel>>>pythonmanage.pyalexa_custom_slotsHOUSE_LIST:gryffindorhufflepuffravenclawslytherinThere is also a convience that will print each of this grouped by app name>>>pythonmanage.pyalexa...Alloftheabovedataoutput...Utterances can be added to your function’s docstring seperating them from the
regular docstring by placing them after ‘—‘.Each line after ‘—’ will be added as an utterance.When defining utterances with variables in them make sure all of the requested
variables in any of the utterances are defined as fields in the slots
for that intent.The django-alexa framework will throw errors when these management commands run
if things seem to be out of place or incorrect.ContributingThe master branch is meant to be stable. I usually work on unstable stuff on a personal branch.Fork the master branch (https://github.com/pycontribs/django-alexa/fork)Create your branch (git checkout -b my-branch)Install required dependencies via pipenv installRun the unit tests via pytest or toxRuntox, this will run black (for formatting code), flake8 for linting and pytestsCommit your changes (git commit -am ‘added fixes for something’)Push to the branch (git push origin my-branch)If you want to merge code from the master branch you can set the upstream like this:git remote add upstream https://github.com/pycontribs/django-alexa.gitCreate a new Pull Request (Travis CI will test your changes)And you’re done!Features, Bug fixes, bug reports and new documentation are all appreciated!See the github issues page for outstanding things that could be worked on.Credits: Kyle Rockman 2016