feat(python): stream iterator request bodies - #515
Open
barjin wants to merge 3 commits into
Open
Conversation
barjin
force-pushed
the
feat/python-streaming-bodies
branch
3 times, most recently
from
August 14, 2026 12:35
de17fef to
0aa0f27
Compare
barjin
force-pushed
the
feat/python-streaming-bodies
branch
from
August 17, 2026 07:39
0aa0f27 to
bd202ad
Compare
barjin
force-pushed
the
feat/python-streaming-bodies
branch
from
August 17, 2026 07:49
bd202ad to
2d3886e
Compare
barjin
force-pushed
the
feat/python-streaming-bodies
branch
from
August 18, 2026 08:59
2d3886e to
7d520db
Compare
barjin
force-pushed
the
feat/python-streaming-bodies
branch
from
August 18, 2026 09:37
7d520db to
61e978c
Compare
`content=` now accepts any (async) iterable of byte chunks, which is fed into the request as the chunks are produced instead of being buffered first. Related: #513
barjin
force-pushed
the
feat/python-streaming-bodies
branch
from
August 18, 2026 10:24
61e978c to
a8f9006
Compare
Pijukatel
approved these changes
Aug 19, 2026
Pijukatel
left a comment
Contributor
There was a problem hiding this comment.
Not sure about those time.sleep(0.1) in tests. Can that get flaky? Isnt there some more robust way to do it?
Binding the socket before starting the thread removes the startup sleep, and the thread is joined even when an assertion fails.
Pijukatel
approved these changes
Aug 19, 2026
| def echoing_server(port_holder: list[int], body_started: threading.Event | None = None) -> None: | ||
| """Echo the raw request (request line, headers and body) back in the response body. | ||
| @contextlib.contextmanager | ||
| def echoing_server(body_started: threading.Event | None = None) -> Iterator[int]: |
Contributor
There was a problem hiding this comment.
Btw. if you move all those helper server functions to a standalone non-test file, you can just import them - to avoid having duplicate echoing_server
Mantisus
approved these changes
Aug 19, 2026
Mantisus
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, only one moment.
| #[pyo3(transparent, annotation = "dict[str, str]")] | ||
| Form(HashMap<String, String>), | ||
| #[pyo3(transparent, annotation = "Iterable[bytes] | AsyncIterable[bytes]")] | ||
| Iterator(PyIterator), |
Collaborator
There was a problem hiding this comment.
str is also iterable, so it matches the Iterator variant and will be processed as an iterator instead of raising an unsupported-type error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Lets
content=take a sync or async iterable of byte chunks and streams it into the request instead of buffering it; stacked on #514.Related: #513