AWS Lex Python Event Autocomplete

AWS Lambda is amazing and WavyCloud’s language of choice is Python. One caveat is the lack of autocomplete on events you receive. So you end up navigating dictionaries and hopefully not have a misspelling of the keys. You also have to remember dictionary structure or keep looking up source event documentation.

We wanted a consistent way to navigate those event dictionaries with auto-complete support. Also, we want to easily construct responses and copy relevant information from input event with autocomplete as well.

We started by having a class that will stores these variables in an object as well as helper functions to create each response type. It was messy but it worked. Eventually we decided to create pylexo to solve that problem.

Pylexo wraps lex lambda events and converts it into an object so you don’t have to remember string keys. All you have to do is pass your event to LexInputEvent.

Here is how pylexo works. For more detailed usage and auto-complete on Slots and Sessions, please visit pylexo documentation at Github

to install

pip install pylexo
import pylexo

def handler(event, context):
    pylexo_event = pylexo.LexInputEvent(event)
    print("messageVersion:   {}".format(pylexo_event.messageVersion))
    print("invocationSource: {}".format(pylexo_event.invocationSource))
    print("userId:           {}".format(pylexo_event.userId))
    print("PickupTime:  {}".format(pylexo_event.currentIntent.slots['PickupTime']))

Boto3 + Pyboto3 = Autocomplete = ❤︎

At Wavycloud we use Amazon Web Services (AWS) to run our service and we use boto3 to manage and automate our infrastructure as well as using it in our Lambda microservices.

One caveat to boto3 is the lack of autocomplete, which means you will have to open boto3 documentation every time you use it just to copy those long function and parameter names.

We decided to fix that by creating pyboto3. We used BeautifulSoup to parse the documentation of boto3 and generate python stub files that will give hint to your IDE.

Here is what will happen when u click ctrl+space after you install pyboto3 and annotate boto3 client.


😮 😮 😮 😮 😮 crazy cool right?

Here is how you can enable this feature.

pip install pyboto3
import boto3
s3 = boto3.client('s3')
""" :type : pyboto3.s3 """
# s3. will give you autocomplete for s3 methods

This is currently limited to boto3 clients and doesn’t work for resources like Paginators, Waiters, Table, etc.

This was currently tested on PyCharm and it worked like a charm. Let us know if it doesn’t work for your favorite IDE.