Repository navigation
feat(documents): stream a document to digitization with no local copy - #2030
paul-ciobanu wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Interrupted uploads or size mismatches can leave separate source iterators unclosed, potentially keeping upstream HTTP connections open across retries.
1 open issue
What changed in this PR
Adds streaming uploads to the UiPath SDK’s IXP extraction methods, allowing documents to be uploaded directly from their source without a local copy.
Changes:
- Introduces
StreamingFileand multipart streaming with known content lengths, size validation, and source reopening on retries. - Adds single-attempt request helpers and tests for streaming behavior and retry handling.
- Bumps
uipath-platformto 0.3.18 and updates lockfiles.
| File | Description |
|---|---|
packages/uipath/uv.lock |
Updates the platform package version. |
packages/uipath-platform/uv.lock |
Records version 0.3.18. |
packages/uipath-platform/tests/services/test_documents_streaming_upload.py |
Tests multipart encoding, uploads, retries, and validation. |
packages/uipath-platform/tests/services/test_documents_service.py |
Updates the expected argument-validation message. |
packages/uipath-platform/tests/services/test_base_service.py |
Tests that single-attempt helpers do not retry. |
packages/uipath-platform/src/uipath/platform/documents/documents.py |
Defines StreamingFile and chunk-source types. |
packages/uipath-platform/src/uipath/platform/documents/_streaming_upload.py |
Builds streaming multipart bodies and validates byte counts. |
packages/uipath-platform/src/uipath/platform/documents/_documents_service.py |
Integrates streaming uploads into IXP extraction. |
packages/uipath-platform/src/uipath/platform/documents/__init__.py |
Exports the new streaming types. |
packages/uipath-platform/src/uipath/platform/common/_base_service.py |
Extracts request helpers without automatic retries. |
packages/uipath-platform/pyproject.toml |
Bumps the package version to 0.3.18. |
Review effort: Balanced
🚨 Heads up:
|
🚨 Heads up:
|
Add a `file_stream: StreamingFile` input to start_ixp_extraction, classify and extract (sync and async). The SDK uploads the document to digitization/start while it reads the source, so the caller needs no local copy and memory use stays flat. - StreamingFile has a name, a size, a content type and an `open` callable that returns sync or async byte chunks. Each attempt calls `open` again and reads from byte 0. - The multipart body is built by hand with a known Content-Length, so the upload is not sent with chunked transfer encoding. - Retryable errors (connect, timeout, 408, 429, 502, 503, 504, 524) retry the upload with a new body. Other errors are not retried. - A source that yields more or fewer bytes than its size fails with a ValueError, and the upload is not retried. - BaseService gets _request_once and _request_once_async: one attempt, no retry. request and request_async call them and do not change. - uipath-platform 0.3.21 -> 0.3.22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2b6e929 to
e90fd7b
Compare
|




What
Every Documents method that uploads a file accepts a new
file_streamargument:start_ixp_extraction,classifyandextract, each with its_asyncform. The SDK uploads the document while it reads it from its source, so the caller needs no local copy.Why
A coded agent that extracts loan documents reads each file from an Orchestrator bucket, writes it to disk, and then uploads it. Some files are larger than 50 MB. With
file_streamthe agent can send the bucket stream directly to DU, with no disk copy and with flat memory use.The existing
file=argument accepts anyIO[bytes], but a network stream does not work with it:fileno()orseek(). A network stream has neither, so httpx sendsTransfer-Encoding: chunked.@retryonrequest_asyncresends the same object. httpx cannot rewind a stream, so a retry sends a partial body or an empty one.read()inside the async client.How
StreamingFile(documents.py) hasname,size(exact bytes),openandcontent_type.openis called once for each attempt and must start from the first byte. The async methods accept anIterable[bytes]or anAsyncIterable[bytes]. The sync method accepts anIterable[bytes]only._streaming_upload.py(new) builds the one-file multipart body by hand, soContent-Lengthis known before the first byte is sent. The body is byte-identical to what httpx writes forfiles={"File": (name, data, content_type)}, so DU sees no change. A test compares the two. If the source yields more or fewer bytes thansize, the upload fails with aValueError. Each opened source is closed after its attempt._start_digitization_stream[_async]sends the body with an explicitContent-Length. The retry loop builds a new body for each attempt, with the same rules asBaseService.request: connect errors, timeouts, and 408, 429, 502, 503, 504 and 524.classifyandextractpassfile_streamthrough_get_document_id[_async], and then wait for digitization as before.file_streamis the last parameter of each method, so existing positional calls do not change. The validators treat it likefileandfile_path: exactly one of the three, and none of them together with aclassification_result.BaseService._request_once[_async]sends one attempt with no retry.requestandrequest_asyncnow call it, and their behavior does not change.Notes for reviewers
_get_caller_componentwalks at most five frames. One extra method betweenrequest_asyncand the client used up one of them, andtest_retrieve_asyncthen got an empty component.requestandrequest_asyncnow resolve the name and pass it down ascaller_component. The existing User-Agent tests pass without change.file=path does the same.file, file_path, file_stream. The existing tests that match it are updated.digitization/startto 160 MB. A larger file gets a 413, which is not retried.uipath-platform0.3.17 -> 0.3.18.Testing
tests/services/test_documents_streaming_upload.py, 53 new tests. They also coverclassifyandextractwith a stream, in sync and async, and the validation rules forfile_stream. The IXP tests cover sync and async paths, an async method with a sync source, byte equality with httpx (including file names with quotes, backslashes and line breaks), a retry that opens the source again, a 413 that is not retried, wrong sizes, and the sync method rejecting an async source._request_once[_async]intest_base_service.py.uipath-platformsuite passes: 2660 passed, 18 skipped.ruff checkandruff format --checkpass onsrcandtests.mypy src testsreports the same 25 errors asmain, and none are new.Content-Lengthand no chunked encoding. Not tested against a live DU tenant.Generated with Claude Code