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

Method stream

httpx/_client.py:828–877  ·  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

826
827 @contextmanager
828 def stream(
829 self,
830 method: str,
831 url: URL | str,
832 *,
833 content: RequestContent | None = None,
834 data: RequestData | None = None,
835 files: RequestFiles | None = None,
836 json: typing.Any | None = None,
837 params: QueryParamTypes | None = None,
838 headers: HeaderTypes | None = None,
839 cookies: CookieTypes | None = None,
840 auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
841 follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
842 timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
843 extensions: RequestExtensions | None = None,
844 ) -> typing.Iterator[Response]:
845 """
846 Alternative to `httpx.request()` that streams the response body
847 instead of loading it into memory at once.
848
849 **Parameters**: See `httpx.request`.
850
851 See also: [Streaming Responses][0]
852
853 [0]: /quickstart#streaming-responses
854 """
855 request = self.build_request(
856 method=method,
857 url=url,
858 content=content,
859 data=data,
860 files=files,
861 json=json,
862 params=params,
863 headers=headers,
864 cookies=cookies,
865 timeout=timeout,
866 extensions=extensions,
867 )
868 response = self.send(
869 request=request,
870 auth=auth,
871 follow_redirects=follow_redirects,
872 stream=True,
873 )
874 try:
875 yield response
876 finally:
877 response.close()
878
879 def send(
880 self,

Callers 11

streamFunction · 0.45
mainFunction · 0.45
test_pool_timeoutFunction · 0.45
test_streamFunction · 0.45
test_stream_responseFunction · 0.45
test_stream_iteratorFunction · 0.45
test_raw_iteratorFunction · 0.45
test_stream_responseFunction · 0.45

Calls 3

sendMethod · 0.95
build_requestMethod · 0.80
closeMethod · 0.45

Tested by 9

test_pool_timeoutFunction · 0.36
test_streamFunction · 0.36
test_stream_responseFunction · 0.36
test_stream_iteratorFunction · 0.36
test_raw_iteratorFunction · 0.36
test_stream_responseFunction · 0.36