def get_client_session( loop: asyncio.AbstractEventLoop) -> aiohttp.ClientSession: """Get a shared ClientSession object that can be reused. If none exists yet it will create one using the passed-in loop. :param loop: an active (i.e. not closed) asyncio event loop :return: a ClientSession instance that can be used to do HTTP requests """ try: return loop._bravado_asyncio_client_session # type: ignore except AttributeError: client_session = aiohttp.ClientSession(loop=loop) loop._bravado_asyncio_client_session = client_session # type: ignore return client_session