Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support streaming requests, which return an IO object rather than par… #725

Merged
merged 3 commits into from
Jun 21, 2021

Conversation

dcr-stripe
Copy link
Contributor

@dcr-stripe dcr-stripe commented Jun 10, 2021

…sing JSON.

Notify

r? @richardm-stripe

Summary

Adds a new request_stream method to StripeObject, ApiRequestor and HTTPClient. When this is used instead of request, an object which extends IOBase will be returned with the response body (implementation differs per HTTP client). Clients will then be able to use this stream to pipe content elsewhere. For errors, we still parse the JSON and raise as appropriate. As part of this, we also had to update custom method decorators to support using request_stream.

Client library methods which return a binary format will use the request_stream method to get a StripeStreamResponse.

While this change is not breaking by itself, as soon as we add a method that uses this we will need to release a new major version as custom HTTPClient implementations will need to implement request_stream.

Motivation

The motivation for this is an upcoming /pdf method that will return a pdf instead of JSON.

Test plan

Added unit tests to ensure that we wire the IO objects appropriately for each HTTP client.

We'll want to add a more concrete test which uses a stripe-mock endpoint that returns an actual PDF to make sure this works as expected across all supported Python versions.

In the interim, I manually tested this by changing an API call to return a stream and making sure that it works as expected for each HTTP client.

@dcr-stripe dcr-stripe changed the title [WIP] Support streaming requests, which return an IO object rather than par… Support streaming requests, which return an IO object rather than par… Jun 21, 2021
@dcr-stripe dcr-stripe merged commit e5790e1 into master Jun 21, 2021
@dcr-stripe dcr-stripe deleted the dcr-binary-streaming branch June 21, 2021 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants