Add option to disable cookie persistence in Client/AsyncClient
Author: fastilyCreated Dec 8, 2023Updated Feb 10, 2026
Labelsenhancement
Initially raised as discussion #1533
I've been using httpx's AsyncClient as a web spider, however I have noticed that cookies are automatically persisted and there's no easy way to disable this. My workaround has been to subclass python's http.cookiejar.CookieJar like so:
from http.cookiejar import CookieJar
class NullCookieJar(CookieJar):
"""A CookieJar that rejects all cookies."""
def extract_cookies(self, *_):
"""For extracting and saving cookies. This implementation does nothing"""
pass
def set_cookie(self, _):
"""Normally for setting a cookie. This implementation does nothing"""
passWould it be possible to:
- add an option to disable cookie persistence to
Client/AsyncClientor - include this implementation of
NullCookieJarinhttpxas a utility class?
Thanks!
Source: encode/httpx