Python SDKResources

Identify

Python SDK - Identify resource API reference

Identify resource for document type identification operations.

Identify

Synchronous document identification operations.

Example:

client = Client(api_key="...")
result = client.identify.run(file=Path("document.pdf"))
print(f"Type: {result.document_type.code}")
print(f"Confidence: {result.document_type.confidence}")

Arguments:

  • client: The parent client instance.

Methods:

get_status

def get_status(self, identification_id: str) -> IdentificationStatus

Get the status of an asynchronous identification.

Arguments:

  • identification_id: The identification ID returned by run_async().

Returns:

The current identification status.

Example:

status = client.identify.get_status("id_abc123")
if status.is_success():
    print(status.document_type.name)

run

def run(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] | None = None) -> IdentificationResult

Identify the type of a document synchronously.

Sends a document to the API and returns the identified document type with confidence scores.

Arguments:

  • file: File to identify (Path, bytes, or file-like object).
  • url: URL of the document to identify (alternative to file).
  • file_base64: Base64-encoded document (alternative to file).
  • content_type: Content type of the file. Auto-detected if not provided.
  • document_type_code_options: List of document type codes to limit identification to. If provided, the API will only consider these document types when identifying.

Returns:

The identification result with document type and alternatives.

Raises:

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

Example:

result = client.identify.run(file=Path("unknown.pdf"))
print(f"Identified as: {result.document_type.name}")
for alt in result.alternatives:
    print(f"  Alternative: {alt.name} ({alt.confidence:.2%})")

# Limit to specific document types
result = client.identify.run(
    file=Path("statement.pdf"),
    document_type_code_options=["cartola_cc", "cartola_tc"]
)

run_async

def run_async(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] | None = None) -> IdentificationStatus

Start an asynchronous document identification.

Initiates an identification job and returns immediately with an ID. Use get_status() to poll for completion.

Arguments:

  • file: File to identify (Path, bytes, or file-like object).
  • url: URL of the document to identify (alternative to file).
  • file_base64: Base64-encoded document (alternative to file).
  • content_type: Content type of the file. Auto-detected if not provided.
  • document_type_code_options: List of document type codes to limit identification to.

Returns:

The initial identification status with identification_id.

Example:

status = client.identify.run_async(file=Path("document.pdf"))
final = status.wait()
print(f"Type: {final.document_type.code}")

Properties:

  • with_raw_response: Access methods that return raw HTTP responses.

AsyncIdentify

Asynchronous document identification operations.

Example:

async with AsyncClient(api_key="...") as client:
    result = await client.identify.run(file=Path("document.pdf"))
    print(f"Type: {result.document_type.code}")

Arguments:

  • client: The parent async client instance.

Methods:

get_status

async def get_status(self, identification_id: str) -> IdentificationStatus

Get the status of an asynchronous identification.

Arguments:

  • identification_id: The identification ID returned by run_async().

Returns:

The current identification status.

run

async def run(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] | None = None) -> IdentificationResult

Identify the type of a document asynchronously.

Arguments:

  • file: File to identify (Path, bytes, or file-like object).
  • url: URL of the document to identify (alternative to file).
  • file_base64: Base64-encoded document (alternative to file).
  • content_type: Content type of the file. Auto-detected if not provided.
  • document_type_code_options: List of document type codes to limit identification to.

Returns:

The identification result with document type and alternatives.

run_async

async def run_async(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] | None = None) -> IdentificationStatus

Start an asynchronous document identification.

Arguments:

  • file: File to identify (Path, bytes, or file-like object).
  • url: URL of the document to identify (alternative to file).
  • file_base64: Base64-encoded document (alternative to file).
  • content_type: Content type of the file. Auto-detected if not provided.
  • document_type_code_options: List of document type codes to limit identification to.

Returns:

The initial identification status with identification_id.

Properties:

  • with_raw_response: Access methods that return raw HTTP responses.

On this page