Skip to content

[REQ][python] Allow streaming large response bodies #16640

@robertschweizer

Description

@robertschweizer

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

  1. 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.
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions