Split
Python SDK reference for the Split resource — methods, parameters, and return types for the DocuTray API.
Split resource: one file with several documents into typed segments.
AsyncSplit
Split a file into typed segments (async client).
Example:
>>> async with AsyncClient() as client:
... split = await client.split.create(
... file=Path("bundle.pdf"), document_type_code_options=["factura"]
... )
... result = await split.wait_async()Arguments:
client: The parent async client instance.
Methods:
create
async def create(self, *, file: FileInput | None = None, url: str | None = None, file_base64: str | None = None, content_type: str | None = None, document_type_code_options: list[str], document_metadata: dict[str, Any] | None = None) -> SplitStatusStart a split. See Split.create.
get_status
async def get_status(self, split_id: str) -> SplitStatusGet the status of a split. See Split.get_status.
wait
async def wait(self, split_id: str, *, poll_interval: float | None = None, timeout: float | None = None, on_status: Callable[[SplitStatus], None] | Callable[[SplitStatus], Awaitable[None]] | None = None) -> SplitStatusPoll a split until it finishes. See Split.wait.
Properties:
with_raw_response: Access methods that return raw HTTP responses.
Split
Split a file that holds several documents into typed segments.
Split is asynchronous only and does not extract data: crop each segment
with docutray.split.crop_segment and convert it.
Example:
>>> split = client.split.create(
... file=Path("bundle.pdf"),
... document_type_code_options=["factura", "boleta"],
... )
>>> result = split.wait()
>>> if result.is_success():
... for segment in result.segments or []:
... print(segment.pages.start, segment.document_type.code)Arguments:
client: The parent client instance.
Methods:
create
def create(self, *, file: FileInput | None = None, url: str | None = None, file_base64: str | None = None, content_type: str | None = None, document_type_code_options: list[str], document_metadata: dict[str, Any] | None = None) -> SplitStatusStart a split.
Arguments:
file: File to split (Path, bytes, or file-like object). PDF up to 100
pages, or a single-page image.
url: Public URL of the file (alternative to file).
file_base64: Base64-encoded file, or a data URI (alternative to file).
content_type: Content type of the file. Auto-detected if not provided.
document_type_code_options: 1 to 20 candidate document type codes,
without otro (it is always a candidate).
document_metadata: JSON object returned as-is in the status and the
SPLIT_* webhooks, up to 64 KB. The key _split is reserved.
With file= (multipart) its values must be strings, numbers,
booleans or None; nested values need url= or
file_base64=.
Returns:
The queued split (status == "ENQUEUED"); call wait() on it.
Raises:
ValueError: If no file input is given or the candidates are invalid. PermissionDeniedError: If some candidates are not accessible.
get_status
def get_status(self, split_id: str) -> SplitStatusGet the status of a split and, on SUCCESS, its segments.
Arguments:
split_id: The split_id returned by create.
wait
def wait(self, split_id: str, *, poll_interval: float | None = None, timeout: float | None = None, on_status: Callable[[SplitStatus], None] | None = None) -> SplitStatusPoll a split until SUCCESS or FAILED and return that status.
Useful when only the split_id is at hand (for example in a webhook
handler). A failed split is returned, not raised.
timeout defaults to 1800 seconds (30 minutes), longer than for
conversions: a split of 100 pages can take over 25 minutes. A timeout
does not cancel the split: call wait(split_id) again to resume,
never create() again (that starts and bills a second split).
Raises:
APITimeoutError: If the split doesn't finish within timeout.
Properties:
with_raw_response: Access methods that return raw HTTP responses.