MCPcopy
hub / github.com/encode/httpx / stream

Method stream

httpx/_client.py:1543–1592  ·  view source on GitHub ↗

Alternative to `httpx.request()` that streams the response body instead of loading it into memory at once. **Parameters**: See `httpx.request`. See also: [Streaming Responses][0] [0]: /quickstart#streaming-responses

(
        self,
        method: str,
        url: URL | str,
        *,
        content: RequestContent | None = None,
        data: RequestData | None = None,
        files: RequestFiles | None = None,
        json: typing.Any | None = None,
        params: QueryParamTypes | None = None,
        headers: HeaderTypes | None = None,
        cookies: CookieTypes | None = None,
        auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
        follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
        timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
        extensions: RequestExtensions | None = None,
    )

Source from the content-addressed store, hash-verified

1541
1542 @asynccontextmanager
1543 async def stream(
1544 self,
1545 method: str,
1546 url: URL | str,
1547 *,
1548 content: RequestContent | None = None,
1549 data: RequestData | None = None,
1550 files: RequestFiles | None = None,
1551 json: typing.Any | None = None,
1552 params: QueryParamTypes | None = None,
1553 headers: HeaderTypes | None = None,
1554 cookies: CookieTypes | None = None,
1555 auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
1556 follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
1557 timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
1558 extensions: RequestExtensions | None = None,
1559 ) -> typing.AsyncIterator[Response]:
1560 """
1561 Alternative to `httpx.request()` that streams the response body
1562 instead of loading it into memory at once.
1563
1564 **Parameters**: See `httpx.request`.
1565
1566 See also: [Streaming Responses][0]
1567
1568 [0]: /quickstart#streaming-responses
1569 """
1570 request = self.build_request(
1571 method=method,
1572 url=url,
1573 content=content,
1574 data=data,
1575 files=files,
1576 json=json,
1577 params=params,
1578 headers=headers,
1579 cookies=cookies,
1580 timeout=timeout,
1581 extensions=extensions,
1582 )
1583 response = await self.send(
1584 request=request,
1585 auth=auth,
1586 follow_redirects=follow_redirects,
1587 stream=True,
1588 )
1589 try:
1590 yield response
1591 finally:
1592 await response.aclose()
1593
1594 async def send(
1595 self,

Callers

nothing calls this directly

Calls 3

sendMethod · 0.95
build_requestMethod · 0.80
acloseMethod · 0.45

Tested by

no test coverage detected