{"id":958,"hash":"53935381c6e4a762c818cd72db9a1ce56f6ee8ae231dfced97951272eb2628ca","pattern":"python-asyncio TypeError: object dict can&#39;t be used in &#39;await&#39; expression","full_message":"I am using a third party module to retrieve data from an API. I simply would like to asynchronously await the module to return the data which occasionally takes several seconds and freezes up my app. However, when I try to await a call to that module I receive the TypeError:\n\nTypeError: object dict can't be used in 'await' expression\n\nimport thirdPartyAPIwrapper\n\nasync def getData():\n    retrienveData = await thirdPartyAPIWrapper.data()\n    return await retrieveData\n\ndef main():\n    loop = asncio.get_event_loop()\n    data = loop.run_until_complete(getData())\n    loop.close\n    return data\n\nWhy can I not await a type('dict')? Is there a way around this?\nIf async/await with asyncio will not work with a third party module that doesn't return a coroutine then what are my other options?","ecosystem":"pypi","package_name":"python-asyncio","package_version":null,"solution":"Only asynchronous (defined with async def) functions can be awaited. Whole idea is that such functions are written special way what makes possible to run (await) them without blocking event loop.\n\nIf you want to get result from common (defined with def) function that takes some considerable time to be executed you have these options:\n\nrewrite this whole function to be asynchronous\ncall this function in another thread and await for result asynchronously\ncall this function in another process and await for result asynchronously\n\nUsually you want to choose second option. \n\nHere's example of how to do it:\n\nimport asyncio\nimport time\nfrom concurrent.futures import ThreadPoolExecutor\n\n_executor = ThreadPoolExecutor(1)\n\ndef sync_blocking():\n    time.sleep(2)\n\nasync def hello_world():\n    # run blocking function in another thread,\n    # and wait for it's result:\n    await loop.run_in_executor(_executor, sync_blocking)\n\nloop = asyncio.get_event_loop()\nloop.run_until_complete(hello_world())\nloop.close()\n\nPlease, read this answer about how asyncio works. I think it'll help you much.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/49822552/python-asyncio-typeerror-object-dict-cant-be-used-in-await-expression","votes":94,"created_at":"2026-04-19T04:52:05.809156+00:00","updated_at":"2026-04-19T04:52:05.809156+00:00"}