Python SDKResources

Convert

Python SDK - Convert resource API reference

Convert resource for document conversion operations.

AsyncConvert

Asynchronous document conversion operations.

Example:

>>> async with AsyncClient(api_key="...") as client:
    ...     result = await client.convert.run(
    ...         file=Path("invoice.pdf"),
    ...         document_type_code="invoice"
    ...     )
    ...     print(result.data)

Arguments:

client: The parent async client instance.

Methods:

get_status

def get_status(self, conversion_id: str) -> ConversionStatus

Get the status of an asynchronous conversion.

Arguments:

conversion_id: The conversion ID returned by run_async().

Returns:

The current conversion status.

run

def run(self, document_type_code: str, file: FileInput | None = None, url: str | None = None, file_base64: str | None = None, content_type: str | None = None, document_metadata: dict[str, Any] | None = None) -> ConversionResult

Convert a document asynchronously.

Arguments:

document_type_code: The document type code to use for conversion. file: File to convert (Path, bytes, or file-like object). url: URL of the document to convert (alternative to file). file_base64: Base64-encoded document (alternative to file). content_type: Content type of the file. Auto-detected if not provided. document_metadata: Additional metadata to include with the document.

Returns:

The conversion result with extracted data.

run_async

def run_async(self, document_type_code: str, file: FileInput | None = None, url: str | None = None, file_base64: str | None = None, content_type: str | None = None, document_metadata: dict[str, Any] | None = None) -> ConversionStatus

Start an asynchronous document conversion.

Arguments:

document_type_code: The document type code to use for conversion. file: File to convert (Path, bytes, or file-like object). url: URL of the document to convert (alternative to file). file_base64: Base64-encoded document (alternative to file). content_type: Content type of the file. Auto-detected if not provided. document_metadata: Additional metadata to include with the document.

Returns:

The initial conversion status with conversion_id.

Properties:

  • with_raw_response : Access methods that return raw HTTP responses.

Convert

Synchronous document conversion operations.

Example:

>>> client = Client(api_key="...")
    >>> result = client.convert.run(
    ...     file=Path("invoice.pdf"),
    ...     document_type_code="invoice"
    ... )
    >>> print(result.data)

Arguments:

client: The parent client instance.

Methods:

get_status

def get_status(self, conversion_id: str) -> ConversionStatus

Get the status of an asynchronous conversion.

Arguments:

conversion_id: The conversion ID returned by run_async().

Returns:

The current conversion status.

Example:

>>> status = client.convert.get_status("conv_abc123")
    >>> if status.is_success():
    ...     print(status.data)

run

def run(self, document_type_code: str, file: FileInput | None = None, url: str | None = None, file_base64: str | None = None, content_type: str | None = None, document_metadata: dict[str, Any] | None = None) -> ConversionResult

Convert a document synchronously.

Sends a document to the API and waits for the conversion result. This is suitable for small documents that process quickly.

Arguments:

document_type_code: The document type code to use for conversion. file: File to convert (Path, bytes, or file-like object). url: URL of the document to convert (alternative to file). file_base64: Base64-encoded document (alternative to file). content_type: Content type of the file. Auto-detected if not provided. document_metadata: Additional metadata to include with the document.

Returns:

The conversion result with extracted data.

Raises:

ValueError: If no file input is provided. BadRequestError: If the request is invalid. AuthenticationError: If the API key is invalid.

Example:

>>> result = client.convert.run(
    ...     file=Path("invoice.pdf"),
    ...     document_type_code="invoice"
    ... )
    >>> print(result.data["total"])

run_async

def run_async(self, document_type_code: str, file: FileInput | None = None, url: str | None = None, file_base64: str | None = None, content_type: str | None = None, document_metadata: dict[str, Any] | None = None) -> ConversionStatus

Start an asynchronous document conversion.

Initiates a conversion job and returns immediately with a conversion ID. Use get_status() to poll for completion, or call wait() on the result.

Arguments:

document_type_code: The document type code to use for conversion. file: File to convert (Path, bytes, or file-like object). url: URL of the document to convert (alternative to file). file_base64: Base64-encoded document (alternative to file). content_type: Content type of the file. Auto-detected if not provided. document_metadata: Additional metadata to include with the document.

Returns:

The initial conversion status with conversion_id.

Example:

>>> status = client.convert.run_async(
    ...     file=Path("large_document.pdf"),
    ...     document_type_code="invoice"
    ... )
    >>> print(f"Conversion ID: {status.conversion_id}")
    >>> # Poll for completion
    >>> final = status.wait()

Properties:

  • with_raw_response : Access methods that return raw HTTP responses.

On this page