DocuTray

Split Types

Type definitions for Split in the DocuTray Python SDK — request and response models, fields, and enums.

Types for split operations (one file with several documents into segments).

SplitStatusType

SplitStatusType = Literal['ENQUEUED', 'PROCESSING', 'SUCCESS', 'FAILED']

Status of a split. A split ends in SUCCESS or FAILED (not ERROR).

SplitConfidenceLevel

SplitConfidenceLevel = Literal['high', 'medium', 'low']

Confidence of a segment: the lowest among its parts.

SplitBox

A box on a page as displayed, from 0 to 1, origin at the top-left corner.

PDF rotation and crop box are applied, and EXIF orientation for images. The box has no margin: add one before cropping (see docutray.split.expand_box).

Fields:

  • model_config: Any

  • x0: float

  • x1: float

  • y0: float

  • y1: float

Methods:

is_full_page

def is_full_page(self) -> bool

True for {x0: 0, y0: 0, x1: 1, y1: 1}.

SplitPages

First and last page of a segment, 1-based and inclusive.

Fields:

  • end: int

  • model_config: Any

  • start: int

SplitRegion

Beta. One part of a segment on one page.

Fields:

  • box: SplitBox - Where the part is on the page.

  • model_config: Any

  • page: int - 1-based page number.

SplitSegment

One document found in the file.

Segments follow the file in order and cover every page; two consecutive segments can share their border page.

Fields:

  • document_type: SplitSegmentDocumentType

  • flags: SplitSegmentFlags

  • index: int - Position of the segment, starting at 0.

  • model_config: Any

  • pages: SplitPages

  • regions: list[SplitRegion] | None - Beta. Where the segment is on each of its pages, or None when no location is known. A page without a region is never shared: send it whole.

SplitSegmentDocumentType

The document type of a segment.

Fields:

  • code: str - One of the candidates sent with the split, or otro.

  • confidence_level: SplitConfidenceLevel - The lowest confidence among the parts of the segment.

  • evidence: str | None - Why a new document starts where the segment starts.

  • model_config: Any

  • name: str - Name of the document type.

SplitSegmentFlags

Flags of a segment.

Fields:

  • model_config: Any

  • multiple_documents_on_page: bool - True when a page of the segment has more than one part (region).

SplitStatus

Status of a split.

Returned by split.create() (status == "ENQUEUED", with status_url) and by split.get_status() (with segments on SUCCESS and error on FAILED).

Fields:

  • document_metadata: dict[str, Any] | None - The document_metadata sent with the split, as-is.

  • document_type_code_options: list[str] | None - The candidates sent with the split (without the implicit otro).

  • error: str | None - Present when the status is FAILED.

  • model_config: Any

  • page_count: int | None - Pages of the file.

  • request_timestamp: datetime | None

  • response_timestamp: datetime | None - Present when the status is SUCCESS or FAILED.

  • segments: list[SplitSegment] | None - Present when the status is SUCCESS.

  • split_id: str - Unique split ID.

  • status: SplitStatusType - Current status.

  • status_url: str | None - URL of the status endpoint (in the response of create()).

Methods:

is_complete

def is_complete(self) -> bool

Check if the split reached a final status (SUCCESS or FAILED).

is_failed

def is_failed(self) -> bool

Check if the split failed.

is_success

def is_success(self) -> bool

Check if the split succeeded.

wait

def wait(self, *, poll_interval: float | None = None, timeout: float | None = None, on_status: Callable[[SplitStatus], None] | None = None) -> SplitStatus

Wait for the split to finish by polling.

Arguments:

poll_interval: Seconds between status checks. Defaults to 2.0; must be greater than 0 (0 would poll without pause into the rate limit). timeout: Maximum seconds to wait. Defaults to 1800.0 (30 minutes): a split of 100 pages can take over 25 minutes. A timeout does not cancel the split: resume with client.split.wait(split_id), never with a new create() (it would be billed again). on_status: Optional callback invoked with each status update.

Returns:

The final status. A failed split is returned with status == "FAILED" (check is_failed()); it is not raised.

Raises:

APITimeoutError: If the split doesn't finish within timeout. ValueError: If this status wasn't created by the split resource.

wait_async

async def wait_async(self, *, poll_interval: float | None = None, timeout: float | None = None, on_status: Callable[[SplitStatus], None] | Callable[[SplitStatus], Awaitable[None]] | None = None) -> SplitStatus

Wait for the split to finish by polling (async version).

Arguments:

poll_interval: Seconds between status checks. Defaults to 2.0; must be greater than 0 (0 would poll without pause into the rate limit). timeout: Maximum seconds to wait. Defaults to 1800.0 (30 minutes): a split of 100 pages can take over 25 minutes. A timeout does not cancel the split: resume with client.split.wait(split_id), never with a new create() (it would be billed again). on_status: Optional callback (sync or async) invoked with each update.

Returns:

The final status; a failed split is returned, not raised.

Raises:

APITimeoutError: If the split doesn't finish within timeout.

On this page