Skip to content

module

Class info

🛈 DocStrings

Resolve which httpx flavour (httpx2 or legacy httpx) to use.

HTTPX_MODULE_NAMES module-attribute

HTTPX_MODULE_NAMES = ('httpx2', 'httpx')

Supported httpx flavours, in order of preference.

get_httpx_module

get_httpx_module(name: str | None = None) -> ModuleType

Return the httpx module to use.

Parameters:

Name Type Description Default
name str | None

Explicit module name ("httpx2" or "httpx"). If omitted, httpx2 is preferred and legacy httpx is used as a fallback.

None

Raises:

Type Description
ImportError

If no httpx flavour is installed.

Source code in src/anyenv/download/httpx_backend/module.py
def get_httpx_module(name: str | None = None) -> ModuleType:
    """Return the httpx module to use.

    Args:
        name: Explicit module name ("httpx2" or "httpx"). If omitted, httpx2 is
              preferred and legacy httpx is used as a fallback.

    Raises:
        ImportError: If no httpx flavour is installed.
    """
    if name is not None:
        return importlib.import_module(name)
    for candidate in HTTPX_MODULE_NAMES:
        if importlib.util.find_spec(candidate):
            return importlib.import_module(candidate)
    msg = "No httpx flavour installed. Install `anyenv[httpx2]` (recommended)."
    raise ImportError(msg)