-
-
Notifications
You must be signed in to change notification settings - Fork 856
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
Stream interface #1550
Stream interface #1550
Conversation
NB.This change also allows us to trivially drop the kinda-implementation-detail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I take this as essentially moving from Iterable
/AsyncIterable
which are somewhat too low-level / not super user-friendly, to well-defined HTTPX interfaces. I think I quite like that. At least no strong "no", and I agree the resulting close-handling is more intuitive as a result.
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
@florimondmanca That's it, yup. Just a nicer more usable interface at the Transport API level. We don't expect the vast majority of our users to be working with that directly, but it's probably nicer for cases where folks are really digging in. It would also potentially allow us to address Seth's comment here at a future date...
...because we could also add support for Although there's also also reasons we might not really want to go that route, which I'm not going to go into unless/until that convo actually gets raised as a prospect. Either ways around, it's clearly a more file-like API, even if chunk size is declared at a transport-init level, rather than per-read. |
Righty, let's push on with this... |
Looks good, is this basically the same as the previous functionality, but pulled into httpx? Wasn't over the moon about the close function in |
It does, doesn't it? |
This pull request allows us to compare the following two alternatives...
stream
as a plain primitiveIterable[bytes]
/AsyncIterable[bytes]
, withclose
/aclose
extensions for handling close callbacks.httpx.SyncByteStream
/httpx.AsyncByteStream
interfaces for streams.Note that the
request.stream
andresponse.stream
interfaces also change as a result of this.The pros of this approach are that the Transport API presents a more natural interface...
Before:
After:
Standard case:
Streaming case:
The cons of this approach are that we're adding
httpx.SyncByteStream
andhttpx.AsyncByteStream
instead of the "handle_request
is just plain datatypes everywhere". We're also adding thehttpx.ByteStream()
class for the simple concrete bytes-only case.Having had a bunch of time to think over the three possible cases...
close
/aclose
extensions to handle resource closing.My feel is that this one probably hits the sweet spot of "nice low-level interface" while still being neatly usable and obvious from a usability perspective.
It's also lower impact if we want to update httpcore with an equivalent interface, since encode/httpcore#296 in it's current state already matches up with this. (But gets more complex if we start adding in
close
/aclose
extensions.)