Microsoft Azure Document Intelligence client library for analyzing text and structured data from documents with machine learning
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Comprehensive data structures for representing extracted document content, model metadata, and operation results across both legacy Form Recognizer API and modern Document Intelligence API.
Fundamental types for representing spatial information, document layout, and SDK utilities.
class Point:
"""Coordinate point in document space."""
x: float # X-coordinate
y: float # Y-coordinate
class BoundingRegion:
"""Bounding region with page reference."""
page_number: int # Page number (1-based)
polygon: List[float] # Polygon coordinates [x1, y1, x2, y2, ...]
# Long-running operation support
class LROPoller:
"""Long-running operation poller for tracking async operations."""
def result(self, timeout: Optional[int] = None) -> Any: ...
def status(self) -> str: ...
def done(self) -> bool: ...
def wait(self, timeout: Optional[int] = None) -> None: ...
def cancel(self) -> None: ...
class DocumentModelAdministrationLROPoller(LROPoller):
"""Specialized LRO poller for model administration operations."""
# Paging support for list operations
class ItemPaged:
"""Paged collection for list operations."""
def __iter__(self): ...
def by_page(self): ...
class AsyncItemPaged:
"""Async paged collection for list operations."""
def __aiter__(self): ...
def by_page(self): ...
# Async LRO Pollers
class AsyncLROPoller:
"""Async long-running operation poller."""
async def result(self, timeout: Optional[int] = None) -> Any: ...
def status(self) -> str: ...
def done(self) -> bool: ...
async def wait(self, timeout: Optional[int] = None) -> None: ...
async def cancel(self) -> None: ...
class AsyncDocumentModelAdministrationLROPoller(AsyncLROPoller):
"""Specialized async LRO poller for model administration operations."""
# Authentication types (from azure.core.credentials and azure.identity)
class TokenCredential:
"""Token-based credential for Azure Active Directory authentication."""
class AsyncTokenCredential:
"""Async token-based credential for Azure Active Directory authentication."""
class AzureKeyCredential:
"""API key-based credential for authentication."""
def __init__(self, key: str): ...
def update(self, key: str) -> None: ...Data structures used by Form Recognizer API v2.1 and below for representing form analysis results.
class RecognizedForm:
"""Result of form recognition operation."""
form_type: str # Type of form recognized
form_type_confidence: Optional[float] # Confidence in form type prediction
fields: Dict[str, FormField] # Extracted fields by name
pages: List[FormPage] # Page-level information
page_range: FormPageRange # Range of pages analyzed
class FormField:
"""Extracted field from form."""
value: Any # Extracted value (text, number, date, etc.)
value_type: FieldValueType # Type of extracted value
label_data: Optional[FieldData] # Information about field label
value_data: Optional[FieldData] # Information about field value
confidence: Optional[float] # Confidence score (0-1)
class FieldData:
"""Spatial and content information for form elements."""
page_number: int # Page number (1-based)
text: str # Text content
bounding_box: List[Point] # Bounding box coordinates
field_elements: Optional[List[FormElement]] # Constituent elementsclass FormPage:
"""Page-level information from form analysis."""
page_number: int # Page number (1-based)
text_angle: Optional[float] # Text angle in radians
width: float # Page width
height: float # Page height
unit: LengthUnit # Unit of measurement (pixel, inch)
tables: Optional[List[FormTable]] # Tables found on page
lines: Optional[List[FormLine]] # Text lines on page
words: Optional[List[FormWord]] # Individual words on page
selection_marks: Optional[List[FormSelectionMark]] # Selection marks on page
class FormLine:
"""Text line in document."""
text: str # Line text content
bounding_box: List[Point] # Line bounding box
words: List[FormWord] # Words in the line
appearance: Optional[TextAppearance] # Text styling information
class FormWord:
"""Individual word in document."""
text: str # Word text
bounding_box: List[Point] # Word bounding box
confidence: Optional[float] # Recognition confidence
page_number: Optional[int] # Page number
class FormSelectionMark:
"""Selection mark (checkbox, radio button) in document."""
state: str # "selected", "unselected"
bounding_box: List[Point] # Mark bounding box
confidence: Optional[float] # Recognition confidence
page_number: Optional[int] # Page numberclass FormTable:
"""Table structure in form."""
row_count: int # Number of rows
column_count: int # Number of columns
cells: List[FormTableCell] # Table cells
bounding_box: Optional[List[Point]] # Table bounding box
page_number: Optional[int] # Page number
class FormTableCell:
"""Cell within a form table."""
text: str # Cell text content
row_index: int # Row index (0-based)
column_index: int # Column index (0-based)
row_span: Optional[int] # Number of rows spanned
column_span: Optional[int] # Number of columns spanned
bounding_box: List[Point] # Cell bounding box
confidence: Optional[float] # Recognition confidence
field_elements: Optional[List[FormElement]] # Constituent elements
is_header: Optional[bool] # Whether cell is a header
is_footer: Optional[bool] # Whether cell is a footer
page_number: Optional[int] # Page numberclass CustomFormModel:
"""Information about a custom trained model."""
model_id: str # Unique model identifier
status: CustomFormModelStatus # Model status (Creating, Ready, Invalid)
training_started_on: datetime # Training start time
training_completed_on: Optional[datetime] # Training completion time
submodels: List[CustomFormSubmodel] # Model subcomponents
errors: Optional[List[FormRecognizerError]] # Training errors
training_documents: Optional[List[TrainingDocumentInfo]] # Training data info
properties: Optional[CustomFormModelProperties] # Additional properties
model_name: Optional[str] # User-assigned model name
class CustomFormSubmodel:
"""Submodel within a custom form model."""
form_type: str # Form type identifier
accuracy: Optional[float] # Model accuracy
fields: Optional[Dict[str, CustomFormModelField]] # Field definitions
model_id: Optional[str] # Associated model ID
class CustomFormModelField:
"""Field definition in custom model."""
field_name: str # Field name
label: Optional[str] # Field label
accuracy: Optional[float] # Field extraction accuracy
class CustomFormModelInfo:
"""Summary information about custom model."""
model_id: str # Model identifier
status: CustomFormModelStatus # Current model status
training_started_on: datetime # Training start time
training_completed_on: Optional[datetime] # Training completion time
properties: Optional[CustomFormModelProperties] # Model properties
model_name: Optional[str] # User-assigned name
class TrainingDocumentInfo:
"""Information about training document."""
name: str # Document name
status: TrainingStatus # Training status for this document
page_count: int # Number of pages
errors: Optional[List[FormRecognizerError]] # Document-specific errors
model_id: Optional[str] # Associated model ID
class AccountProperties:
"""Form Recognizer account information."""
custom_model_count: int # Current number of custom models
custom_model_limit: int # Maximum allowed custom modelsData structures used by Document Intelligence API 2022-08-31 and later for advanced document analysis.
class AnalyzeResult:
"""Complete document analysis result."""
api_version: str # API version used
model_id: str # Model used for analysis
content: str # Extracted text content
pages: Optional[List[DocumentPage]] # Page-level information
paragraphs: Optional[List[DocumentParagraph]] # Paragraph information
tables: Optional[List[DocumentTable]] # Table structures
key_value_pairs: Optional[List[DocumentKeyValuePair]] # Key-value pairs
entities: Optional[List[Any]] # Named entities (not fully typed)
styles: Optional[List[DocumentStyle]] # Text styling information
languages: Optional[List[DocumentLanguage]] # Language information
documents: Optional[List[AnalyzedDocument]] # Structured documents
warnings: Optional[List[Any]] # Analysis warnings
class AnalyzedDocument:
"""Structured document within analysis result."""
doc_type: str # Document type
bounding_regions: Optional[List[BoundingRegion]] # Document boundaries
spans: Optional[List[DocumentSpan]] # Text spans
fields: Optional[Dict[str, DocumentField]] # Extracted fields
confidence: Optional[float] # Document type confidenceclass DocumentPage:
"""Page-level document information."""
page_number: int # Page number (1-based)
angle: Optional[float] # Page rotation angle
width: Optional[float] # Page width
height: Optional[float] # Page height
unit: Optional[str] # Unit of measurement
spans: Optional[List[DocumentSpan]] # Text spans on page
words: Optional[List[DocumentWord]] # Words on page
selection_marks: Optional[List[DocumentSelectionMark]] # Selection marks
lines: Optional[List[DocumentLine]] # Text lines
barcodes: Optional[List[DocumentBarcode]] # Barcodes (API v2023-07-31)
formulas: Optional[List[DocumentFormula]] # Formulas (API v2023-07-31)
class DocumentWord:
"""Individual word in document."""
content: str # Word text
polygon: Optional[List[float]] # Word boundary polygon
span: DocumentSpan # Text span reference
confidence: Optional[float] # Recognition confidence
class DocumentLine:
"""Text line in document."""
content: str # Line text
polygon: Optional[List[float]] # Line boundary polygon
spans: Optional[List[DocumentSpan]] # Text spans
class DocumentParagraph:
"""Paragraph in document."""
role: Optional[str] # Paragraph role (title, sectionHeading, etc.)
content: str # Paragraph text
bounding_regions: Optional[List[BoundingRegion]] # Paragraph boundaries
spans: List[DocumentSpan] # Text spans
class DocumentSpan:
"""Text span reference."""
offset: int # Character offset in content
length: int # Span length in charactersclass DocumentBarcode:
"""Barcode information extracted from document."""
kind: str # Barcode type (QRCode, PDF417, UPCA, etc.)
value: str # Decoded barcode value
polygon: Optional[List[float]] # Barcode boundary
span: DocumentSpan # Text span reference
confidence: Optional[float] # Detection confidence
page_number: int # Page number
class DocumentFormula:
"""Mathematical formula in document."""
kind: str # Formula type (inline, display)
value: str # Formula expression (LaTeX format)
polygon: Optional[List[float]] # Formula boundary
span: DocumentSpan # Text span reference
confidence: Optional[float] # Detection confidence
page_number: int # Page numberclass DocumentField:
"""Extracted field from document."""
value_type: str # Field value type
value: Any # Extracted value (varies by type)
content: Optional[str] # Raw text content
bounding_regions: Optional[List[BoundingRegion]] # Field boundaries
spans: Optional[List[DocumentSpan]] # Text spans
confidence: Optional[float] # Extraction confidence
class AddressValue:
"""Structured address value."""
house_number: Optional[str] # House number
po_box: Optional[str] # PO Box
road: Optional[str] # Street name
city: Optional[str] # City name
state: Optional[str] # State/province
postal_code: Optional[str] # Postal/ZIP code
country_region: Optional[str] # Country
street_address: Optional[str] # Full street address
unit: Optional[str] # Unit/apartment number
city_district: Optional[str] # City district
state_district: Optional[str] # State district
suburb: Optional[str] # Suburb
house: Optional[str] # House name
level: Optional[str] # Floor level
class CurrencyValue:
"""Currency amount value."""
amount: float # Numeric amount
symbol: Optional[str] # Currency symbol ($, €, etc.)
code: Optional[str] # Currency code (USD, EUR, etc.)class DocumentTable:
"""Table structure in document."""
row_count: int # Number of rows
column_count: int # Number of columns
cells: List[DocumentTableCell] # Table cells
bounding_regions: Optional[List[BoundingRegion]] # Table boundaries
spans: Optional[List[DocumentSpan]] # Text spans
caption: Optional[str] # Table caption
class DocumentTableCell:
"""Cell within document table."""
kind: Optional[str] # Cell kind (content, rowHeader, columnHeader, etc.)
row_index: int # Row index (0-based)
column_index: int # Column index (0-based)
row_span: Optional[int] # Rows spanned
column_span: Optional[int] # Columns spanned
content: str # Cell text content
bounding_regions: Optional[List[BoundingRegion]] # Cell boundaries
spans: Optional[List[DocumentSpan]] # Text spans
elements: Optional[List[str]] # References to constituent elementsclass DocumentKeyValuePair:
"""Key-value pair extracted from document."""
key: DocumentKeyValueElement # Key element
value: Optional[DocumentKeyValueElement] # Value element
confidence: Optional[float] # Extraction confidence
class DocumentKeyValueElement:
"""Element of key-value pair."""
content: str # Text content
bounding_regions: Optional[List[BoundingRegion]] # Element boundaries
spans: Optional[List[DocumentSpan]] # Text spansclass DocumentLanguage:
"""Language information for document content."""
locale: str # Language locale (e.g., "en-US")
spans: List[DocumentSpan] # Text spans in this language
confidence: Optional[float] # Language detection confidence
class DocumentStyle:
"""Text styling information."""
is_handwritten: Optional[bool] # Whether text is handwritten
similar_font_family: Optional[str] # Similar font family name
font_style: Optional[str] # Font style (normal, italic)
font_weight: Optional[str] # Font weight (normal, bold)
color: Optional[str] # Text color (hex format)
background_color: Optional[str] # Background color (hex format)
spans: List[DocumentSpan] # Text spans with this style
confidence: Optional[float] # Style detection confidence
class DocumentSelectionMark:
"""Selection mark in document."""
state: str # Selection state ("selected", "unselected")
polygon: Optional[List[float]] # Mark boundary
span: DocumentSpan # Text span reference
confidence: Optional[float] # Detection confidenceData structures for model lifecycle management and operation monitoring.
class DocumentModelDetails:
"""Detailed information about document model."""
model_id: str # Model identifier
description: Optional[str] # Model description
created_date_time: datetime # Creation timestamp
api_version: str # API version used to create model
tags: Optional[Dict[str, str]] # Custom tags
doc_types: Optional[Dict[str, DocumentTypeDetails]] # Supported document types
expires_date_time: Optional[datetime] # Model expiration time
class DocumentModelSummary:
"""Summary information about document model."""
model_id: str # Model identifier
description: Optional[str] # Model description
created_date_time: datetime # Creation timestamp
api_version: str # API version
tags: Optional[Dict[str, str]] # Custom tags
expires_date_time: Optional[datetime] # Expiration time
class DocumentTypeDetails:
"""Details about document type supported by model."""
description: Optional[str] # Document type description
build_mode: Optional[str] # Build mode used (template, neural)
field_schema: Optional[Dict[str, Any]] # Field schema definition
field_confidence: Optional[Dict[str, float]] # Field confidence scoresclass DocumentClassifierDetails:
"""Information about document classifier."""
classifier_id: str # Classifier identifier
description: Optional[str] # Classifier description
created_date_time: datetime # Creation timestamp
api_version: str # API version
doc_types: Dict[str, ClassifierDocumentTypeDetails] # Document types
expires_date_time: Optional[datetime] # Expiration time
class ClassifierDocumentTypeDetails:
"""Document type details for classifier."""
source_kind: Optional[str] # Training data source type
azure_blob_source: Optional[BlobSource] # Blob storage source
azure_blob_file_list_source: Optional[BlobFileListSource] # File list source
class BlobSource:
"""Azure Blob Storage source configuration."""
container_url: str # Container URL with SAS token
prefix: Optional[str] # File prefix filter
class BlobFileListSource:
"""Azure Blob Storage file list source."""
container_url: str # Container URL with SAS token
file_list: str # JSON file with file list
class DocumentModelBuildOperationDetails:
"""Details for document model build operations."""
operation_id: str # Operation identifier
status: str # Current status
percent_completed: Optional[int] # Completion percentage
created_date_time: datetime # Creation time
last_updated_date_time: datetime # Last update time
kind: str # Operation type
resource_location: Optional[str] # Resource location
api_version: Optional[str] # API version
tags: Optional[Dict[str, str]] # Operation tags
error: Optional[DocumentAnalysisError] # Error information if failed
result: Optional[DocumentModelDetails] # Operation result if succeededclass OperationSummary:
"""Summary of long-running operation."""
operation_id: str # Operation identifier
status: str # Operation status (notStarted, running, succeeded, failed)
percent_completed: Optional[int] # Completion percentage
created_date_time: datetime # Operation start time
last_updated_date_time: datetime # Last update time
kind: str # Operation kind (documentModelBuild, documentModelCompose, etc.)
resource_location: Optional[str] # Location of created resource
class OperationDetails:
"""Detailed information about operation."""
operation_id: str # Operation identifier
status: str # Current status
percent_completed: Optional[int] # Completion percentage
created_date_time: datetime # Creation time
last_updated_date_time: datetime # Last update time
kind: str # Operation type
resource_location: Optional[str] # Resource location
api_version: Optional[str] # API version
tags: Optional[Dict[str, str]] # Operation tags
error: Optional[DocumentAnalysisError] # Error information if failed
result: Optional[Any] # Operation result if succeeded
class ResourceDetails:
"""Information about Form Recognizer resource."""
custom_document_models: CustomDocumentModelsDetails # Custom model info
neural_document_model_quota: QuotaDetails # Neural model quota
class CustomDocumentModelsDetails:
"""Custom document model quota information."""
count: int # Current number of custom models
limit: int # Maximum allowed custom models
class QuotaDetails:
"""Quota information for specific resource type."""
used: int # Currently used quota
quota: int # Total available quota
quota_resets_on: Optional[datetime] # Quota reset time
class TargetAuthorization:
"""Authorization for model copying."""
target_resource_id: str # Target resource identifier
target_resource_region: str # Target resource region
target_model_id: str # Target model identifier
target_model_location: str # Target model location URL
access_token: str # Access token for copying
expiration_date_time: datetime # Token expiration timeclass FieldValueType(str, Enum):
"""Types of field values that can be extracted."""
STRING = "string"
DATE = "date"
TIME = "time"
PHONE_NUMBER = "phoneNumber"
NUMBER = "number" # Legacy - use FLOAT for new code
FLOAT = "float"
INTEGER = "integer"
SELECTION_MARK = "selectionMark"
COUNTRY_REGION = "countryRegion"
SIGNATURE = "signature"
ARRAY = "array" # Legacy - use LIST for new code
LIST = "list"
OBJECT = "object" # Legacy - use DICTIONARY for new code
DICTIONARY = "dictionary"
CURRENCY = "currency"
ADDRESS = "address"
class LengthUnit(str, Enum):
"""Units of measurement for dimensions."""
PIXEL = "pixel"
INCH = "inch"
class TrainingStatus(str, Enum):
"""Status of training operations."""
SUCCEEDED = "succeeded"
PARTIALLY_SUCCEEDED = "partiallySucceeded"
FAILED = "failed"
class CustomFormModelStatus(str, Enum):
"""Status of custom form models."""
CREATING = "creating"
READY = "ready"
INVALID = "invalid"
class ModelBuildMode(str, Enum):
"""Model building approaches."""
TEMPLATE = "template" # Fast, structured documents
NEURAL = "neural" # Slower, better for varied layouts
class AnalysisFeature(str, Enum):
"""Enhanced analysis features."""
OCR_HIGH_RESOLUTION = "ocrHighResolution"
LANGUAGES = "languages"
BARCODES = "barcodes"
FORMULAS = "formulas"
KEY_VALUE_PAIRS = "keyValuePairs"
STYLE_FONT = "styleFont"class FormRecognizerError:
"""Error information from Form Recognizer API."""
error_code: str # Error code
message: str # Error message
class DocumentAnalysisError:
"""Error information from Document Intelligence API."""
code: str # Error code
message: str # Error message
target: Optional[str] # Error target
details: Optional[List['DocumentAnalysisError']] # Nested errors
innererror: Optional['DocumentAnalysisInnerError'] # Inner error details
class DocumentAnalysisInnerError:
"""Inner error details."""
code: str # Inner error code
message: str # Inner error message
innererror: Optional['DocumentAnalysisInnerError'] # Nested inner error# Legacy API - access form fields
for form in recognized_forms:
vendor_name = form.fields.get("VendorName")
if vendor_name and vendor_name.value:
print(f"Vendor: {vendor_name.value}")
print(f"Confidence: {vendor_name.confidence}")
# Access spatial information
if vendor_name.value_data:
print(f"Location: Page {vendor_name.value_data.page_number}")
bbox = vendor_name.value_data.bounding_box
print(f"Bounding box: {[(p.x, p.y) for p in bbox]}")
# Modern API - access document fields
for document in analyze_result.documents:
vendor_name = document.fields.get("VendorName")
if vendor_name and vendor_name.value:
print(f"Vendor: {vendor_name.value}")
print(f"Confidence: {vendor_name.confidence}")
# Access spatial information
if vendor_name.bounding_regions:
for region in vendor_name.bounding_regions:
print(f"Page {region.page_number}: {region.polygon}")# Legacy API tables
for table in form_page.tables:
print(f"Table: {table.row_count}x{table.column_count}")
for cell in table.cells:
print(f"Cell [{cell.row_index}, {cell.column_index}]: {cell.text}")
# Modern API tables
for table in analyze_result.tables:
print(f"Table: {table.row_count}x{table.column_count}")
if table.caption:
print(f"Caption: {table.caption}")
for cell in table.cells:
kind = cell.kind or "content"
print(f"{kind.title()} [{cell.row_index}, {cell.column_index}]: {cell.content}")Install with Tessl CLI
npx tessl i tessl/pypi-azure-ai-formrecognizer