(
    url: str,
    *,
    lines: bool = False,
    decode_unicode: bool = False,
    chunk_size: int = 1024,
    auth: Optional[Tuple[str, str]] = None,
)
Read data from ``url`` in a stream, either all at once or line-by-line.

    Args:
        url: URL to which a GET request is made for data.
        lines: If False, yield all of the data at once; otherwise, yield data line-by-line.
        decode_unicode: If True, yield data as unicode, where the encoding
            is taken from the HTTP response headers; otherwise, yield bytes.
        chunk_size: Number of bytes read into memory per chunk.
            Because decoding may occur, this is not necessarily the length of each chunk.
        auth: (username, password) pair for simple HTTP authentication required (if at all)
            to access the data at ``url``.

            .. seealso:: http://docs.python-requests.org/en/master/user/authentication/

    Yields:
        If ``lines`` is True, the next line in the response data,
        which is bytes if ``decode_unicode`` is False or unicode otherwise.
        If ``lines`` is False, yields the full response content, either as bytes
        or unicode.
Read data from ``url`` in a stream, either all at once or line-by-line.
Read data from url in a stream either all at once or line - by - line .
def read_http_stream(
    url: str,
    *,
    lines: bool = False,
    decode_unicode: bool = False,
    chunk_size: int = 1024,
    auth: Optional[Tuple[str, str]] = None,
) -> Iterable[str] | Iterable[bytes]:
    """
    Read data from ``url`` in a stream, either all at once or line-by-line.

    Args:
        url: URL to which a GET request is made for data.
        lines: If False, yield all of the data at once; otherwise, yield data line-by-line.
        decode_unicode: If True, yield data as unicode, where the encoding
            is taken from the HTTP response headers; otherwise, yield bytes.
        chunk_size: Number of bytes read into memory per chunk.
            Because decoding may occur, this is not necessarily the length of each chunk.
        auth: (username, password) pair for simple HTTP authentication required (if at all)
            to access the data at ``url``.

            .. seealso:: http://docs.python-requests.org/en/master/user/authentication/

    Yields:
        If ``lines`` is True, the next line in the response data,
        which is bytes if ``decode_unicode`` is False or unicode otherwise.
        If ``lines`` is False, yields the full response content, either as bytes
        or unicode.
    """
    # always close the connection
    with closing(requests.get(url, stream=True, auth=auth)) as r:
        # set fallback encoding if unable to infer from headers
        if r.encoding is None:
            r.encoding = "utf-8"
        if lines is False:
            if decode_unicode is True:
                yield r.text
            else:
                yield r.content
        else:
            lines_ = r.iter_lines(chunk_size=chunk_size, decode_unicode=decode_unicode)
            for line in lines_:
                if line:
                    yield line
def read_http_stream ( url : str , * , lines : bool = False , decode_unicode : bool = False , chunk_size : int = 1024 , auth : Optional [ Tuple [ str , str ] ] = None , ) -> Iterable [ str ] | Iterable [ bytes ] : # always close the connection with closing ( requests . get ( url , stream = True , auth = auth ) ) as r : # set fallback encoding if unable to infer from headers if r . encoding is None : r . encoding = "utf-8" if lines is False : if decode_unicode is True : yield r . text else : yield r . content else : lines_ = r . iter_lines ( chunk_size = chunk_size , decode_unicode = decode_unicode ) for line in lines_ : if line : yield line