Python code to access websockets api

I would like to write some code that would pick up all changes, and forward to another app. I belive I could use the HA websocket api for this, but i get auth errors as I dont know how to write the code.
From the docs I have the code below.

Does anyone know how to extend the code with pasword auth?

#!/usr/bin/python3

Copyright © 2017, Fabian Affolter [email protected]

Released under the ASL 2.0 license. See LICENSE.md file for details.

import asyncio
import asyncws
import json

@asyncio.coroutine
def echo():
websocket = yield from asyncws.connect(‘ws://localhost:8123/api/websocket’)

yield from websocket.send(json.dumps(
    {'id': 1, 'type': 'subscribe_events', 'event_type': 'state_changed'}))

while True:
    message = yield from websocket.recv()
    if message is None:
        break
    print (message)

asyncio.get_event_loop().run_until_complete(echo())
asyncio.get_event_loop().close()

solved it by just adding this code as a second yield:

yield from websocket.send(json.dumps(
{‘type’: ‘auth’, ‘api_password’: ‘Password’}))