Skip to content

feat(documents): stream a document to digitization with no local copy - #2030

Open
paul-ciobanu wants to merge 1 commit into
mainfrom
feat/documents-streaming-digitization
Open

paul-ciobanu wants to merge 1 commit into
mainfrom
feat/documents-streaming-digitization

Conversation

@paul-ciobanu

@paul-ciobanu paul-ciobanu commented Nov 26, 2026 •

Copy link
Copy Markdown

What

Every Documents method that uploads a file accepts a new file_stream argument: start_ixp_extraction, classify and extract, each with its _async form. The SDK uploads the document while it reads it from its source, so the caller needs no local copy.

async def read_blob():
    async with client.stream("GET", read_uri) as response:
        response.raise_for_status()
        async for chunk in response.aiter_bytes(1024 * 1024):
            yield chunk

source = StreamingFile(name="appraisal.pdf", size=57_671_680, open=read_blob,
                       content_type="application/pdf")
await uipath.documents.start_ixp_extraction_async(
    project_name="LoanProject", tag="live", file_stream=source)

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_stream the agent can send the bucket stream directly to DU, with no disk copy and with flat memory use.

The existing file= argument accepts any IO[bytes], but a network stream does not work with it:

Problem Cause
Chunked upload httpx gets the length from fileno() or seek(). A network stream has neither, so httpx sends Transfer-Encoding: chunked.
Broken retry The @retry on request_async resends the same object. httpx cannot rewind a stream, so a retry sends a partial body or an empty one.
Blocked event loop httpx calls a sync read() inside the async client.

How

  • StreamingFile (documents.py) has name, size (exact bytes), open and content_type. open is called once for each attempt and must start from the first byte. The async methods accept an Iterable[bytes] or an AsyncIterable[bytes]. The sync method accepts an Iterable[bytes] only.
  • _streaming_upload.py (new) builds the one-file multipart body by hand, so Content-Length is known before the first byte is sent. The body is byte-identical to what httpx writes for files={"File": (name, data, content_type)}, so DU sees no change. A test compares the two. If the source yields more or fewer bytes than size, the upload fails with a ValueError. Each opened source is closed after its attempt.
  • _start_digitization_stream[_async] sends the body with an explicit Content-Length. The retry loop builds a new body for each attempt, with the same rules as BaseService.request: connect errors, timeouts, and 408, 429, 502, 503, 504 and 524.
  • classify and extract pass file_stream through _get_document_id[_async], and then wait for digitization as before. file_stream is the last parameter of each method, so existing positional calls do not change. The validators treat it like file and file_path: exactly one of the three, and none of them together with a classification_result.
  • BaseService._request_once[_async] sends one attempt with no retry. request and request_async now call it, and their behavior does not change.

Notes for reviewers

  • User-Agent caller name. _get_caller_component walks at most five frames. One extra method between request_async and the client used up one of them, and test_retrieve_async then got an empty component. request and request_async now resolve the name and pass it down as caller_component. The existing User-Agent tests pass without change.
  • Read timeout after the upload. A read timeout after the full body is sent is still retried, so DU can digitize the same file twice. The current file= path does the same.
  • Error message. The "Exactly one of" message now lists file, file_path, file_stream. The existing tests that match it are updated.
  • DU limit. DU limits digitization/start to 160 MB. A larger file gets a 413, which is not retried.
  • uipath-platform 0.3.17 -> 0.3.18.

Testing

  • tests/services/test_documents_streaming_upload.py, 53 new tests. They also cover classify and extract with a stream, in sync and async, and the validation rules for file_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.
  • Two tests for _request_once[_async] in test_base_service.py.
  • The full uipath-platform suite passes: 2660 passed, 18 skipped. ruff check and ruff format --check pass on src and tests. mypy src tests reports the same 25 errors as main, and none are new.
  • Manual check: a 49 MiB stream sent through the real httpx transport to a local HTTP server, in sync and async. It arrived intact, with a Content-Length and no chunked encoding. Not tested against a live DU tenant.

Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings November 26, 2026 11:41
@github-actions github-actions Bot added test:uipath-langchain Triggers tests in the uipath-langchain-python repository test:uipath-integrations labels Nov 26, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 StreamingFile and 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-platform to 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

@paul-ciobanu paul-ciobanu changed the title feat(documents): stream a document to IXP digitization with no local copy feat(documents): stream a document to digitization with no local copy Nov 26, 2026
@github-actions

Copy link
Copy Markdown

🚨 Heads up: uipath-integrations cross-tests are FAILING 🚨

Your changes may break one or more integrations in uipath-integrations-python:

  • uipath-openai-agents
  • uipath-google-adk
  • uipath-agent-framework
  • uipath-llamaindex
  • uipath-pydantic-ai

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

@github-actions

Copy link
Copy Markdown

🚨 Heads up: uipath-langchain cross-tests are FAILING 🚨

Your changes may break the uipath-langchain-python integration.

⚠️ These checks are NOT enforced by branch protection rules. Please review the failures before merging.

🔍 Inspect the failed run →

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>
@paul-ciobanu
paul-ciobanu force-pushed the feat/documents-streaming-digitization branch from 2b6e929 to e90fd7b Compare November 27, 2026 11:28
@sonarqubecloud

Copy link
Copy Markdown

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:uipath-integrations test:uipath-langchain Triggers tests in the uipath-langchain-python repository

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants