from __future__ import print_function	# For Py2/3 compatibility
import async_eel
import random
import asyncio


loop = asyncio.get_event_loop()


@async_eel.expose
async def py_random():
    return random.random()


async def print_num(n):
    """callback of js_random"""
    print('Got this from Javascript:', n)


async def main():
    try:
        async_eel.init('web')
        await async_eel.start('callbacks.html', size=(400, 300))

        # Call Javascript function, and pass explicit callback function
        await async_eel.js_random()(print_num)

        # Do the same with an inline callback
        await async_eel.js_random()(lambda n: print('2Got this from Javascript:', n))
    except Exception:
        import traceback
        traceback.print_exc()


if __name__ == '__main__':
    asyncio.run_coroutine_threadsafe(main(), loop)
    loop.run_forever()

[((7, 7, 7, 31), 'asyncio.get_event_loop', 'asyncio.get_event_loop', ({}, {}), '()', False, 'import asyncio\n'), ((12, 11, 12, 26), 'random.random', 'random.random', ({}, {}), '()', False, 'import random\n'), ((22, 8, 22, 29), 'async_eel.init', 'async_eel.init', ({(22, 23, 22, 28): '"""web"""'}, {}), "('web')", False, 'import async_eel\n'), ((23, 14, 23, 64), 'async_eel.start', 'async_eel.start', (), '', False, 'import async_eel\n'), ((32, 8, 32, 29), 'traceback.print_exc', 'traceback.print_exc', ({}, {}), '()', False, 'import traceback\n'), ((26, 14, 26, 35), 'async_eel.js_random', 'async_eel.js_random', ({}, {}), '()', False, 'import async_eel\n'), ((29, 14, 29, 35), 'async_eel.js_random', 'async_eel.js_random', ({}, {}), '()', False, 'import async_eel\n')]