title: How to use asyncio with httpx for http get and keep the connection start and close
body: <p>I need to fetch http endpoint via lambda job and that will be via asyncio and httpx .I can use context to open close the client however that may slow down the process since I have huge events.</p>
  <p>I have async http invoke like this:</p>
  <pre><code>import httpx
  import asyncio
  
  
  class AsyncHttpSource:
      def __init__(self, url):
          self.url = url
  
      async def get_app_ids(self, client):
          response = await client.get(self.url)
          return response.json()
  
      async def async_invoke(self):
          &quot;&quot;&quot;
          This will invoke the http endpoint and configured default 30s timeout on connect. 5s timeout for all other.
          &quot;&quot;&quot;
          async with httpx.AsyncClient(timeout=httpx.Timeout(5.0, connect=30.0), verify=False) as client:
              tasks = [asyncio.ensure_future(self.get_app_ids(client))]
              result = await asyncio.gather(*tasks)
              return result[0]
  </code></pre>
  <p>how to change to a start and close connection for the async client and better way to improve performance recommended?</p>