Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,
        )
like image 455
Maanaav A Motiramani Avatar asked Apr 16 '26 16:04

Maanaav A Motiramani


1 Answers

Just dont use the context manager.

client = httpx.AsyncClient()
response = await client.get(
    URL,
    params=params,
)

Or if you want to have the same cleanup functionality:

client = httpx.AsyncClient()
try:
    response = await client.get(
        URL,
        params=params,
    )
    # do other stuff
finally:
    await client.aclose()
like image 73
Lucas Adams Avatar answered Apr 18 '26 07:04

Lucas Adams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!