Search code examples
pythonpython-requestshttpx

how to persist sessions in httpx python


We can easily create a persistent session using:

s = requests.Session()

But how to achieve this using httpx library?

async with httpx.AsyncClient() as client:
        response = await client.get(
            URL,
            params=params,
        )

Solution

  • Something like this

    with httpx.Client() as client:
    
        r = client.get('https://example.com')
    

    Source https://www.python-httpx.org/advanced/clients/