[azure-core/corehttp] Add JSONL streaming support#48077
Draft
l0lawrence wants to merge 1 commit into
Draft
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 7 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
l0lawrence
force-pushed
the
l0lawrence-jsonl-stream-followup
branch
from
July 15, 2026 22:47
f10ef48 to
785e97e
Compare
Adds a stream-agnostic Stream/AsyncStream iterator plus JSONLDecoder/AsyncJSONLDecoder to both azure-core (azure.core.streaming) and corehttp (corehttp.streaming), kept in sync. The deserialization_callback receives the response and each decoded event so generated code can support the cls custom-deserializer pattern. Each package includes sync/async tests, test-server JSONL routes, a sample, CHANGELOG entry, and a README section (azure-core also bumps the version to 1.42.0). Based on the design in https://gist.github.com/kristapratico/d330af39962ea05b10384b865e37b36f and the original corehttp prototype in Azure#39478. Part of Azure#38806. Co-authored-by: Krista Pratico <krpratic@microsoft.com> Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
l0lawrence
force-pushed
the
l0lawrence-jsonl-stream-followup
branch
from
July 15, 2026 22:59
785e97e to
8fe667c
Compare
kashifkhan
reviewed
Jul 16, 2026
| for chunk in iter_bytes: | ||
| decoded += decoder.decode(chunk) | ||
| if decoded: | ||
| decoded_lines = decoded.splitlines() |
Member
There was a problem hiding this comment.
I don't think we can use splitlines as is since it breaks on more than just what the JSONL spec specifies https://docs.python.org/3.4/library/stdtypes.html#str.splitlines.
splitlines will treat \u2028 and \u2029 as split but the spec https://www.rfc-editor.org/info/rfc8259/ has it as
certain characters such as U+2028 LINE SEPARATOR and U+2029
PARAGRAPH SEPARATOR are legal in JSON but not JavaScript
So line termination will have to be simply \n and `\r\n'
'{"msg": "a\u2028b"}\n'.splitlines()
['{"msg": "a', 'b"}' # one valid record -> two invalid fragments -> JSONDecodeError
'{"msg": "a\u2028b"}\n'.split("\n")
['{"msg": "a\u2028b"}', ''] # one record + trailing empty from the final \n
json.loads('{"msg": "a\u2028b"}')
{'msg': 'a\u2028b'} # U+2028 preserved inside the string value
kashifkhan
reviewed
Jul 16, 2026
| async def __anext__(self) -> ReturnType_co: | ||
| return await self._iterator.__anext__() | ||
|
|
||
| async def __aiter__(self) -> AsyncIterator[ReturnType_co]: # pylint: disable=invalid-overridden-method |
Member
There was a problem hiding this comment.
I think the iter funcs need to return Self
kashifkhan
reviewed
Jul 16, 2026
| :keyword response: The response object. | ||
| :paramtype response: ~corehttp.rest.AsyncHttpResponse | ||
| :keyword decoder: A decoder to use for the stream. | ||
| :paramtype decoder: ~corehttp.streaming.decoders.AsyncStreamDecoder |
Member
There was a problem hiding this comment.
should it be _decoders here?
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.
Adds JSONL streaming support to both azure-core (
azure.core.streaming) and corehttp (corehttp.streaming), kept in sync so the two implementations stay identical (only therest-path docstrings differ).Ports the design from the design gist and the original corehttp prototype in #39478 (closed unmerged), with the review gaps addressed. Part of #38806.
What's included (per package)
Stream/AsyncStreamstream-agnostic iteratorsJSONLDecoder/AsyncJSONLDecoder(incremental UTF-8 line decoding)deserialization_callbackreceives(response, event)so generated code can support theclscustom-deserializer patternsamples/sample_stream.py)SSE support remains a follow-up, as noted in the original prototype.
Validation (both packages)