-
Notifications
You must be signed in to change notification settings - Fork 259
Expand file tree
/
Copy pathazure.ai.formrecognizer.DocumentAnalysisClient.yml
More file actions
528 lines (478 loc) · 32.8 KB
/
azure.ai.formrecognizer.DocumentAnalysisClient.yml
File metadata and controls
528 lines (478 loc) · 32.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
### YamlMime:PythonClass
uid: azure.ai.formrecognizer.DocumentAnalysisClient
name: DocumentAnalysisClient
fullName: azure.ai.formrecognizer.DocumentAnalysisClient
module: azure.ai.formrecognizer
inheritances:
- azure.ai.formrecognizer._form_base_client.FormRecognizerClientBase
summary: 'DocumentAnalysisClient analyzes information from documents and images, and
classifies documents.
It is the interface to use for analyzing with prebuilt models (receipts, business
cards,
invoices, identity documents, among others), analyzing layout from documents, analyzing
general
document types, and analyzing custom documents with built models (to see a full
list of models
supported by the service, see: [https://aka.ms/azsdk/formrecognizer/models](https://aka.ms/azsdk/formrecognizer/models)).
It provides different
methods based on inputs from a URL and inputs from a stream.
> [!NOTE]
> DocumentAnalysisClient should be used with API versions
>
> 2022-08-31 and up. To use API versions <=v2.1, instantiate a FormRecognizerClient.
>
New in version 2022-08-31: The *DocumentAnalysisClient* and its client methods.'
constructor:
syntax: 'DocumentAnalysisClient(endpoint: str, credential: AzureKeyCredential |
TokenCredential, **kwargs: Any)'
parameters:
- name: endpoint
description: 'Supported Cognitive Services endpoints (protocol and hostname,
for example: [https://westus2.api.cognitive.microsoft.com](https://westus2.api.cognitive.microsoft.com)).'
isRequired: true
types:
- <xref:str>
- name: credential
description: 'Credentials needed for the client to connect to Azure.
This is an instance of AzureKeyCredential if using an API key or a token
credential from <xref:azure.identity>.'
isRequired: true
types:
- <xref:azure.core.credentials.AzureKeyCredential>
- <xref:azure.core.credentials.TokenCredential>
- name: api_version
description: 'The API version of the service to use for requests. It defaults
to the latest service version.
Setting to an older version may result in reduced feature compatibility. To
use API versions
<=v2.1, instantiate a FormRecognizerClient.'
types:
- <xref:str>
- <xref:azure.ai.formrecognizer.DocumentAnalysisApiVersion>
examples:
- "Creating the DocumentAnalysisClient with an endpoint and API key.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_authentication.py )]-->\n\n<!-- literal_block {\"ids\": [],\
\ \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\\samples\\\\v3.2_and_later\\\
\\sample_authentication.py\", \"xml:space\": \"preserve\", \"force\": false, \"\
language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\": false}\
\ -->\n\n````python\n\n from azure.core.credentials import AzureKeyCredential\n\
\ from azure.ai.formrecognizer import DocumentAnalysisClient\n\n endpoint =\
\ os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"]\n key = os.environ[\"AZURE_FORM_RECOGNIZER_KEY\"\
]\n\n document_analysis_client = DocumentAnalysisClient(endpoint, AzureKeyCredential(key))\n\
\n ````\n\nCreating the DocumentAnalysisClient with a token credential.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_authentication.py )]-->\n\n<!-- literal_block {\"ids\": [],\
\ \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\\samples\\\\v3.2_and_later\\\
\\sample_authentication.py\", \"xml:space\": \"preserve\", \"force\": false, \"\
language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\": false}\
\ -->\n\n````python\n\n \"\"\"DefaultAzureCredential will use the values from\
\ these environment\n variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET\n\
\ \"\"\"\n from azure.ai.formrecognizer import DocumentAnalysisClient\n from\
\ azure.identity import DefaultAzureCredential\n\n endpoint = os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"\
]\n credential = DefaultAzureCredential()\n\n document_analysis_client = DocumentAnalysisClient(endpoint,\
\ credential)\n\n ````\n"
methods:
- uid: azure.ai.formrecognizer.DocumentAnalysisClient.begin_analyze_document
name: begin_analyze_document
summary: 'Analyze field text and semantic values from a given document.
New in version 2023-07-31: The *features* keyword argument.'
signature: 'begin_analyze_document(model_id: str, document: bytes | IO[bytes], **kwargs:
Any) -> LROPoller[AnalyzeResult]'
parameters:
- name: model_id
description: 'A unique model identifier can be passed in as a string.
Use this to specify the custom model ID or prebuilt model ID. Prebuilt model
IDs supported
can be found here: [https://aka.ms/azsdk/formrecognizer/models](https://aka.ms/azsdk/formrecognizer/models)'
isRequired: true
types:
- <xref:str>
- name: document
description: 'File stream or bytes. For service supported file types,
see: [https://aka.ms/azsdk/formrecognizer/supportedfiles](https://aka.ms/azsdk/formrecognizer/supportedfiles).'
isRequired: true
types:
- <xref:bytes>
- <xref:typing.IO>[<xref:bytes>]
- name: pages
description: 'Custom page numbers for multi-page documents(PDF/TIFF). Input the
page numbers
and/or ranges of pages you want to get in the result. For a range of pages,
use a hyphen, like
*pages="1-3, 5-6"*. Separate each page number or range with a comma.'
types:
- <xref:str>
- name: locale
description: 'Locale hint of the input document.
See supported locales here: [https://aka.ms/azsdk/formrecognizer/supportedlocales](https://aka.ms/azsdk/formrecognizer/supportedlocales).'
types:
- <xref:str>
- name: features
description: Document analysis features to enable.
types:
- <xref:list>[<xref:str>]
return:
description: 'An instance of an LROPoller. Call *result()* on the poller
object to return a <xref:azure.ai.formrecognizer.AnalyzeResult>.'
types:
- <xref:azure.core.polling.LROPoller>[<xref:azure.ai.formrecognizer.AnalyzeResult>]
exceptions:
- type: azure.core.exceptions.HttpResponseError
examples:
- "Analyze an invoice. For more samples see the *samples* folder.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_analyze_invoices.py )]-->\n\n<!-- literal_block {\"ids\"\
: [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\\samples\\\\v3.2_and_later\\\
\\sample_analyze_invoices.py\", \"xml:space\": \"preserve\", \"force\": false,\
\ \"language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\"\
: false} -->\n\n````python\n\n from azure.core.credentials import AzureKeyCredential\n\
\ from azure.ai.formrecognizer import DocumentAnalysisClient\n\n endpoint\
\ = os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"]\n key = os.environ[\"AZURE_FORM_RECOGNIZER_KEY\"\
]\n\n document_analysis_client = DocumentAnalysisClient(\n endpoint=endpoint,\
\ credential=AzureKeyCredential(key)\n )\n with open(path_to_sample_documents,\
\ \"rb\") as f:\n poller = document_analysis_client.begin_analyze_document(\n\
\ \"prebuilt-invoice\", document=f, locale=\"en-US\"\n )\n invoices\
\ = poller.result()\n\n for idx, invoice in enumerate(invoices.documents):\n\
\ print(f\"--------Analyzing invoice #{idx + 1}--------\")\n vendor_name\
\ = invoice.fields.get(\"VendorName\")\n if vendor_name:\n print(\n\
\ f\"Vendor Name: {vendor_name.value} has confidence: {vendor_name.confidence}\"\
\n )\n vendor_address = invoice.fields.get(\"VendorAddress\")\n\
\ if vendor_address:\n print(\n f\"Vendor Address:\
\ {vendor_address.value} has confidence: {vendor_address.confidence}\"\n \
\ )\n vendor_address_recipient = invoice.fields.get(\"VendorAddressRecipient\"\
)\n if vendor_address_recipient:\n print(\n f\"\
Vendor Address Recipient: {vendor_address_recipient.value} has confidence: {vendor_address_recipient.confidence}\"\
\n )\n customer_name = invoice.fields.get(\"CustomerName\")\n\
\ if customer_name:\n print(\n f\"Customer Name:\
\ {customer_name.value} has confidence: {customer_name.confidence}\"\n \
\ )\n customer_id = invoice.fields.get(\"CustomerId\")\n if customer_id:\n\
\ print(\n f\"Customer Id: {customer_id.value} has confidence:\
\ {customer_id.confidence}\"\n )\n customer_address = invoice.fields.get(\"\
CustomerAddress\")\n if customer_address:\n print(\n \
\ f\"Customer Address: {customer_address.value} has confidence: {customer_address.confidence}\"\
\n )\n customer_address_recipient = invoice.fields.get(\"CustomerAddressRecipient\"\
)\n if customer_address_recipient:\n print(\n f\"\
Customer Address Recipient: {customer_address_recipient.value} has confidence:\
\ {customer_address_recipient.confidence}\"\n )\n invoice_id =\
\ invoice.fields.get(\"InvoiceId\")\n if invoice_id:\n print(\n\
\ f\"Invoice Id: {invoice_id.value} has confidence: {invoice_id.confidence}\"\
\n )\n invoice_date = invoice.fields.get(\"InvoiceDate\")\n \
\ if invoice_date:\n print(\n f\"Invoice Date: {invoice_date.value}\
\ has confidence: {invoice_date.confidence}\"\n )\n invoice_total\
\ = invoice.fields.get(\"InvoiceTotal\")\n if invoice_total:\n \
\ print(\n f\"Invoice Total: {invoice_total.value} has confidence:\
\ {invoice_total.confidence}\"\n )\n due_date = invoice.fields.get(\"\
DueDate\")\n if due_date:\n print(f\"Due Date: {due_date.value}\
\ has confidence: {due_date.confidence}\")\n purchase_order = invoice.fields.get(\"\
PurchaseOrder\")\n if purchase_order:\n print(\n \
\ f\"Purchase Order: {purchase_order.value} has confidence: {purchase_order.confidence}\"\
\n )\n billing_address = invoice.fields.get(\"BillingAddress\"\
)\n if billing_address:\n print(\n f\"Billing Address:\
\ {billing_address.value} has confidence: {billing_address.confidence}\"\n \
\ )\n billing_address_recipient = invoice.fields.get(\"BillingAddressRecipient\"\
)\n if billing_address_recipient:\n print(\n f\"\
Billing Address Recipient: {billing_address_recipient.value} has confidence: {billing_address_recipient.confidence}\"\
\n )\n shipping_address = invoice.fields.get(\"ShippingAddress\"\
)\n if shipping_address:\n print(\n f\"Shipping\
\ Address: {shipping_address.value} has confidence: {shipping_address.confidence}\"\
\n )\n shipping_address_recipient = invoice.fields.get(\"ShippingAddressRecipient\"\
)\n if shipping_address_recipient:\n print(\n f\"\
Shipping Address Recipient: {shipping_address_recipient.value} has confidence:\
\ {shipping_address_recipient.confidence}\"\n )\n print(\"Invoice\
\ items:\")\n for idx, item in enumerate(invoice.fields.get(\"Items\").value):\n\
\ print(f\"...Item #{idx + 1}\")\n item_description = item.value.get(\"\
Description\")\n if item_description:\n print(\n \
\ f\"......Description: {item_description.value} has confidence:\
\ {item_description.confidence}\"\n )\n item_quantity\
\ = item.value.get(\"Quantity\")\n if item_quantity:\n \
\ print(\n f\"......Quantity: {item_quantity.value} has confidence:\
\ {item_quantity.confidence}\"\n )\n unit = item.value.get(\"\
Unit\")\n if unit:\n print(f\"......Unit: {unit.value}\
\ has confidence: {unit.confidence}\")\n unit_price = item.value.get(\"\
UnitPrice\")\n if unit_price:\n unit_price_code = unit_price.value.code\
\ if unit_price.value.code else \"\"\n print(\n \
\ f\"......Unit Price: {unit_price.value}{unit_price_code} has confidence: {unit_price.confidence}\"\
\n )\n product_code = item.value.get(\"ProductCode\")\n\
\ if product_code:\n print(\n f\"......Product\
\ Code: {product_code.value} has confidence: {product_code.confidence}\"\n \
\ )\n item_date = item.value.get(\"Date\")\n if\
\ item_date:\n print(\n f\"......Date: {item_date.value}\
\ has confidence: {item_date.confidence}\"\n )\n tax =\
\ item.value.get(\"Tax\")\n if tax:\n print(f\"......Tax:\
\ {tax.value} has confidence: {tax.confidence}\")\n amount = item.value.get(\"\
Amount\")\n if amount:\n print(\n f\"\
......Amount: {amount.value} has confidence: {amount.confidence}\"\n \
\ )\n subtotal = invoice.fields.get(\"SubTotal\")\n if subtotal:\n\
\ print(f\"Subtotal: {subtotal.value} has confidence: {subtotal.confidence}\"\
)\n total_tax = invoice.fields.get(\"TotalTax\")\n if total_tax:\n\
\ print(\n f\"Total Tax: {total_tax.value} has confidence:\
\ {total_tax.confidence}\"\n )\n previous_unpaid_balance = invoice.fields.get(\"\
PreviousUnpaidBalance\")\n if previous_unpaid_balance:\n print(\n\
\ f\"Previous Unpaid Balance: {previous_unpaid_balance.value} has\
\ confidence: {previous_unpaid_balance.confidence}\"\n )\n amount_due\
\ = invoice.fields.get(\"AmountDue\")\n if amount_due:\n print(\n\
\ f\"Amount Due: {amount_due.value} has confidence: {amount_due.confidence}\"\
\n )\n service_start_date = invoice.fields.get(\"ServiceStartDate\"\
)\n if service_start_date:\n print(\n f\"Service\
\ Start Date: {service_start_date.value} has confidence: {service_start_date.confidence}\"\
\n )\n service_end_date = invoice.fields.get(\"ServiceEndDate\"\
)\n if service_end_date:\n print(\n f\"Service End\
\ Date: {service_end_date.value} has confidence: {service_end_date.confidence}\"\
\n )\n service_address = invoice.fields.get(\"ServiceAddress\"\
)\n if service_address:\n print(\n f\"Service Address:\
\ {service_address.value} has confidence: {service_address.confidence}\"\n \
\ )\n service_address_recipient = invoice.fields.get(\"ServiceAddressRecipient\"\
)\n if service_address_recipient:\n print(\n f\"\
Service Address Recipient: {service_address_recipient.value} has confidence: {service_address_recipient.confidence}\"\
\n )\n remittance_address = invoice.fields.get(\"RemittanceAddress\"\
)\n if remittance_address:\n print(\n f\"Remittance\
\ Address: {remittance_address.value} has confidence: {remittance_address.confidence}\"\
\n )\n remittance_address_recipient = invoice.fields.get(\"RemittanceAddressRecipient\"\
)\n if remittance_address_recipient:\n print(\n \
\ f\"Remittance Address Recipient: {remittance_address_recipient.value} has confidence:\
\ {remittance_address_recipient.confidence}\"\n )\n\n ````\n\nAnalyze\
\ a custom document. For more samples see the *samples* folder.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_analyze_custom_documents.py )]-->\n\n<!-- literal_block\
\ {\"ids\": [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\"\
: [], \"source\": \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\
\\Lib\\\\site-packages\\\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\
\\samples\\\\v3.2_and_later\\\\sample_analyze_custom_documents.py\", \"xml:space\"\
: \"preserve\", \"force\": false, \"language\": \"python\", \"highlight_args\"\
: {\"linenostart\": 1}, \"linenos\": false} -->\n\n````python\n\n from azure.core.credentials\
\ import AzureKeyCredential\n from azure.ai.formrecognizer import DocumentAnalysisClient\n\
\n endpoint = os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"]\n key = os.environ[\"\
AZURE_FORM_RECOGNIZER_KEY\"]\n model_id = os.getenv(\"CUSTOM_BUILT_MODEL_ID\"\
, custom_model_id)\n\n document_analysis_client = DocumentAnalysisClient(\n\
\ endpoint=endpoint, credential=AzureKeyCredential(key)\n )\n\n # Make\
\ sure your document's type is included in the list of document types the custom\
\ model can analyze\n with open(path_to_sample_documents, \"rb\") as f:\n \
\ poller = document_analysis_client.begin_analyze_document(\n model_id=model_id,\
\ document=f\n )\n result = poller.result()\n\n for idx, document in\
\ enumerate(result.documents):\n print(f\"--------Analyzing document #{idx\
\ + 1}--------\")\n print(f\"Document has type {document.doc_type}\")\n\
\ print(f\"Document has document type confidence {document.confidence}\"\
)\n print(f\"Document was analyzed with model with ID {result.model_id}\"\
)\n for name, field in document.fields.items():\n field_value\
\ = field.value if field.value else field.content\n print(\n \
\ f\"......found field of type '{field.value_type}' with value '{field_value}'\
\ and with confidence {field.confidence}\"\n )\n\n # iterate over\
\ tables, lines, and selection marks on each page\n for page in result.pages:\n\
\ print(f\"\\nLines found on page {page.page_number}\")\n for line\
\ in page.lines:\n print(f\"...Line '{line.content}'\")\n for\
\ word in page.words:\n print(f\"...Word '{word.content}' has a confidence\
\ of {word.confidence}\")\n if page.selection_marks:\n print(f\"\
\\nSelection marks found on page {page.page_number}\")\n for selection_mark\
\ in page.selection_marks:\n print(\n f\"...Selection\
\ mark is '{selection_mark.state}' and has a confidence of {selection_mark.confidence}\"\
\n )\n\n for i, table in enumerate(result.tables):\n print(f\"\
\\nTable {i + 1} can be found on page:\")\n for region in table.bounding_regions:\n\
\ print(f\"...{region.page_number}\")\n for cell in table.cells:\n\
\ print(\n f\"...Cell[{cell.row_index}][{cell.column_index}]\
\ has text '{cell.content}'\"\n )\n print(\"-----------------------------------\"\
)\n\n ````\n"
- uid: azure.ai.formrecognizer.DocumentAnalysisClient.begin_analyze_document_from_url
name: begin_analyze_document_from_url
summary: 'Analyze field text and semantic values from a given document.
The input must be the location (URL) of the document to be analyzed.
New in version 2023-07-31: The *features* keyword argument.'
signature: 'begin_analyze_document_from_url(model_id: str, document_url: str, **kwargs:
Any) -> LROPoller[AnalyzeResult]'
parameters:
- name: model_id
description: 'A unique model identifier can be passed in as a string.
Use this to specify the custom model ID or prebuilt model ID. Prebuilt model
IDs supported
can be found here: [https://aka.ms/azsdk/formrecognizer/models](https://aka.ms/azsdk/formrecognizer/models)'
isRequired: true
types:
- <xref:str>
- name: document_url
description: 'The URL of the document to analyze. The input must be a valid, properly
encoded (i.e. encode special characters, such as empty spaces), and publicly
accessible URL.
For service supported file types, see: [https://aka.ms/azsdk/formrecognizer/supportedfiles](https://aka.ms/azsdk/formrecognizer/supportedfiles).'
isRequired: true
types:
- <xref:str>
- name: pages
description: 'Custom page numbers for multi-page documents(PDF/TIFF). Input the
page numbers
and/or ranges of pages you want to get in the result. For a range of pages,
use a hyphen, like
*pages="1-3, 5-6"*. Separate each page number or range with a comma.'
types:
- <xref:str>
- name: locale
description: 'Locale hint of the input document.
See supported locales here: [https://aka.ms/azsdk/formrecognizer/supportedlocales](https://aka.ms/azsdk/formrecognizer/supportedlocales).'
types:
- <xref:str>
- name: features
description: Document analysis features to enable.
types:
- <xref:list>[<xref:str>]
return:
description: 'An instance of an LROPoller. Call *result()* on the poller
object to return a <xref:azure.ai.formrecognizer.AnalyzeResult>.'
types:
- <xref:azure.core.polling.LROPoller>[<xref:azure.ai.formrecognizer.AnalyzeResult>]
exceptions:
- type: azure.core.exceptions.HttpResponseError
examples:
- "Analyze a receipt. For more samples see the *samples* folder.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_analyze_receipts_from_url.py )]-->\n\n<!-- literal_block\
\ {\"ids\": [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\"\
: [], \"source\": \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\
\\Lib\\\\site-packages\\\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\
\\samples\\\\v3.2_and_later\\\\sample_analyze_receipts_from_url.py\", \"xml:space\"\
: \"preserve\", \"force\": false, \"language\": \"python\", \"highlight_args\"\
: {\"linenostart\": 1}, \"linenos\": false} -->\n\n````python\n\n from azure.core.credentials\
\ import AzureKeyCredential\n from azure.ai.formrecognizer import DocumentAnalysisClient\n\
\n endpoint = os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"]\n key = os.environ[\"\
AZURE_FORM_RECOGNIZER_KEY\"]\n\n document_analysis_client = DocumentAnalysisClient(\n\
\ endpoint=endpoint, credential=AzureKeyCredential(key)\n )\n url =\
\ \"https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-receipt.png\"\
\n poller = document_analysis_client.begin_analyze_document_from_url(\n \
\ \"prebuilt-receipt\", document_url=url\n )\n receipts = poller.result()\n\
\n for idx, receipt in enumerate(receipts.documents):\n print(f\"--------Analysis\
\ of receipt #{idx + 1}--------\")\n print(f\"Receipt type: {receipt.doc_type\
\ if receipt.doc_type else 'N/A'}\")\n merchant_name = receipt.fields.get(\"\
MerchantName\")\n if merchant_name:\n print(\n f\"\
Merchant Name: {merchant_name.value} has confidence: \"\n f\"{merchant_name.confidence}\"\
\n )\n transaction_date = receipt.fields.get(\"TransactionDate\"\
)\n if transaction_date:\n print(\n f\"Transaction\
\ Date: {transaction_date.value} has confidence: \"\n f\"{transaction_date.confidence}\"\
\n )\n if receipt.fields.get(\"Items\"):\n print(\"\
Receipt items:\")\n for idx, item in enumerate(receipt.fields.get(\"\
Items\").value):\n print(f\"...Item #{idx + 1}\")\n \
\ item_description = item.value.get(\"Description\")\n if item_description:\n\
\ print(\n f\"......Item Description:\
\ {item_description.value} has confidence: \"\n f\"{item_description.confidence}\"\
\n )\n item_quantity = item.value.get(\"Quantity\"\
)\n if item_quantity:\n print(\n \
\ f\"......Item Quantity: {item_quantity.value} has confidence: \"\n\
\ f\"{item_quantity.confidence}\"\n )\n\
\ item_price = item.value.get(\"Price\")\n if item_price:\n\
\ print(\n f\"......Individual Item Price:\
\ {item_price.value} has confidence: \"\n f\"{item_price.confidence}\"\
\n )\n item_total_price = item.value.get(\"TotalPrice\"\
)\n if item_total_price:\n print(\n \
\ f\"......Total Item Price: {item_total_price.value} has confidence:\
\ \"\n f\"{item_total_price.confidence}\"\n \
\ )\n subtotal = receipt.fields.get(\"Subtotal\")\n if subtotal:\n\
\ print(f\"Subtotal: {subtotal.value} has confidence: {subtotal.confidence}\"\
)\n tax = receipt.fields.get(\"TotalTax\")\n if tax:\n print(f\"\
Total tax: {tax.value} has confidence: {tax.confidence}\")\n tip = receipt.fields.get(\"\
Tip\")\n if tip:\n print(f\"Tip: {tip.value} has confidence: {tip.confidence}\"\
)\n total = receipt.fields.get(\"Total\")\n if total:\n \
\ print(f\"Total: {total.value} has confidence: {total.confidence}\")\n \
\ print(\"--------------------------------------\")\n\n ````\n"
- uid: azure.ai.formrecognizer.DocumentAnalysisClient.begin_classify_document
name: begin_classify_document
summary: 'Classify a document using a document classifier. For more information
on how to build
a custom classifier model, see [https://aka.ms/azsdk/formrecognizer/buildclassifiermodel](https://aka.ms/azsdk/formrecognizer/buildclassifiermodel).
New in version 2023-07-31: The *begin_classify_document* client method.'
signature: 'begin_classify_document(classifier_id: str, document: bytes | IO[bytes],
**kwargs: Any) -> LROPoller[AnalyzeResult]'
parameters:
- name: classifier_id
description: A unique document classifier identifier can be passed in as a string.
isRequired: true
types:
- <xref:str>
- name: document
description: 'File stream or bytes. For service supported file types, see:
[https://aka.ms/azsdk/formrecognizer/supportedfiles](https://aka.ms/azsdk/formrecognizer/supportedfiles).'
isRequired: true
types:
- <xref:bytes>
- <xref:typing.IO>[<xref:bytes>]
return:
description: 'An instance of an LROPoller. Call *result()* on the poller
object to return a <xref:azure.ai.formrecognizer.AnalyzeResult>.'
types:
- <xref:azure.core.polling.LROPoller>[<xref:azure.ai.formrecognizer.AnalyzeResult>]
exceptions:
- type: azure.core.exceptions.HttpResponseError
examples:
- "Classify a document. For more samples see the *samples* folder.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_classify_document.py )]-->\n\n<!-- literal_block {\"ids\"\
: [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\": [], \"source\"\
: \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\\Lib\\\\site-packages\\\
\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\\samples\\\\v3.2_and_later\\\
\\sample_classify_document.py\", \"xml:space\": \"preserve\", \"force\": false,\
\ \"language\": \"python\", \"highlight_args\": {\"linenostart\": 1}, \"linenos\"\
: false} -->\n\n````python\n\n from azure.core.credentials import AzureKeyCredential\n\
\ from azure.ai.formrecognizer import DocumentAnalysisClient\n\n endpoint\
\ = os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"]\n key = os.environ[\"AZURE_FORM_RECOGNIZER_KEY\"\
]\n classifier_id = os.getenv(\"CLASSIFIER_ID\", classifier_id)\n\n document_analysis_client\
\ = DocumentAnalysisClient(\n endpoint=endpoint, credential=AzureKeyCredential(key)\n\
\ )\n with open(path_to_sample_documents, \"rb\") as f:\n poller = document_analysis_client.begin_classify_document(\n\
\ classifier_id, document=f\n )\n result = poller.result()\n\
\n print(\"----Classified documents----\")\n for doc in result.documents:\n\
\ print(\n f\"Found document of type '{doc.doc_type or 'N/A'}'\
\ with a confidence of {doc.confidence} contained on \"\n f\"the following\
\ pages: {[region.page_number for region in doc.bounding_regions]}\"\n )\n\
\n ````\n"
- uid: azure.ai.formrecognizer.DocumentAnalysisClient.begin_classify_document_from_url
name: begin_classify_document_from_url
summary: 'Classify a given document with a document classifier. For more information
on how to build
a custom classifier model, see [https://aka.ms/azsdk/formrecognizer/buildclassifiermodel](https://aka.ms/azsdk/formrecognizer/buildclassifiermodel).
The input must be the location (URL) of the document to be classified.
New in version 2023-07-31: The *begin_classify_document_from_url* client method.'
signature: 'begin_classify_document_from_url(classifier_id: str, document_url: str,
**kwargs: Any) -> LROPoller[AnalyzeResult]'
parameters:
- name: classifier_id
description: A unique document classifier identifier can be passed in as a string.
isRequired: true
types:
- <xref:str>
- name: document_url
description: 'The URL of the document to classify. The input must be a valid,
properly
encoded (i.e. encode special characters, such as empty spaces), and publicly
accessible URL
of one of the supported formats: [https://aka.ms/azsdk/formrecognizer/supportedfiles](https://aka.ms/azsdk/formrecognizer/supportedfiles).'
isRequired: true
types:
- <xref:str>
return:
description: 'An instance of an LROPoller. Call *result()* on the poller
object to return a <xref:azure.ai.formrecognizer.AnalyzeResult>.'
types:
- <xref:azure.core.polling.LROPoller>[<xref:azure.ai.formrecognizer.AnalyzeResult>]
exceptions:
- type: azure.core.exceptions.HttpResponseError
examples:
- "Classify a document. For more samples see the *samples* folder.<!--[!code-python[Main](les\\\
v3.2_and_later\\sample_classify_document_from_url.py )]-->\n\n<!-- literal_block\
\ {\"ids\": [], \"classes\": [], \"names\": [], \"dupnames\": [], \"backrefs\"\
: [], \"source\": \"C:\\\\hostedtoolcache\\\\windows\\\\Python\\\\3.11.5\\\\x64\\\
\\Lib\\\\site-packages\\\\py2docfx\\\\dist_temp\\\\5\\\\azure-ai-formrecognizer-3.3.0\\\
\\samples\\\\v3.2_and_later\\\\sample_classify_document_from_url.py\", \"xml:space\"\
: \"preserve\", \"force\": false, \"language\": \"python\", \"highlight_args\"\
: {\"linenostart\": 1}, \"linenos\": false} -->\n\n````python\n\n from azure.core.credentials\
\ import AzureKeyCredential\n from azure.ai.formrecognizer import DocumentAnalysisClient\n\
\n endpoint = os.environ[\"AZURE_FORM_RECOGNIZER_ENDPOINT\"]\n key = os.environ[\"\
AZURE_FORM_RECOGNIZER_KEY\"]\n classifier_id = os.getenv(\"CLASSIFIER_ID\",\
\ classifier_id)\n\n document_analysis_client = DocumentAnalysisClient(\n \
\ endpoint=endpoint, credential=AzureKeyCredential(key)\n )\n\n url =\
\ \"https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/forms/IRS-1040.pdf\"\
\n\n poller = document_analysis_client.begin_classify_document_from_url(\n \
\ classifier_id, document_url=url\n )\n result = poller.result()\n\n\
\ print(\"----Classified documents----\")\n for doc in result.documents:\n\
\ print(\n f\"Found document of type '{doc.doc_type or 'N/A'}'\
\ with a confidence of {doc.confidence} contained on \"\n f\"the following\
\ pages: {[region.page_number for region in doc.bounding_regions]}\"\n )\n\
\n ````\n"
- uid: azure.ai.formrecognizer.DocumentAnalysisClient.close
name: close
summary: Close the <xref:azure.ai.formrecognizer.DocumentAnalysisClient> session.
signature: close() -> None