When downloading a large response body, e.g. a file, it is useful to only load a chunk of the file into memory at once.
The generated client (pydantic-based, v7.0.1) does not allow streaming responses in this way: When specifying _preload_content=False, this option is passed through to urllib3. But later, urllib3.HTTPResponse.data is accessed to fill ApiResponse.raw_data. This loads the entire response body into memory.
Describe the solution you'd like
- Expose the
urllib3.HTTPResponse instance to callers of the _with_http_info request functions for maximum flexibility. Maybe add this as an extra property urllib3_response to ApiResponse.
- Do not access
urllib3.HTTPResponse.data when constructing the ApiResponse instance. Instead, ApiResponse.raw_data could become a @property that returns self.urllib3_response.data. The decoding done if _preload_content=True can also be moved to the property method.
Describe alternatives you've considered
My workaround is using plain requests to stream large files.
Additional context
When downloading a large response body, e.g. a file, it is useful to only load a chunk of the file into memory at once.
The generated client (pydantic-based, v7.0.1) does not allow streaming responses in this way: When specifying
_preload_content=False, this option is passed through to urllib3. But later,urllib3.HTTPResponse.datais accessed to fillApiResponse.raw_data. This loads the entire response body into memory.Describe the solution you'd like
urllib3.HTTPResponseinstance to callers of the_with_http_inforequest functions for maximum flexibility. Maybe add this as an extra propertyurllib3_responsetoApiResponse.urllib3.HTTPResponse.datawhen constructing theApiResponseinstance. Instead,ApiResponse.raw_datacould become a@propertythat returnsself.urllib3_response.data. The decoding done if_preload_content=Truecan also be moved to the property method.Describe alternatives you've considered
My workaround is using plain
requeststo stream large files.Additional context