Client SDK for Azure Content Understanding.
Project description
azure-cu-sdk Documentation
Project initialized and authored by: Kintu Sangwan (kintu.sangwn.ref@gmail.com)
This SDK solves the need to reliably submit documents to Azure Content Understanding, poll for completion, and retrieve the exact raw response payload for downstream use.
It provides an async REST client, a helper layer for document analysis, and Pydantic models for typed request and response payloads.
Overview
azure_cu_sdk.aio: Async import surface for the client and helper utilities.azure_cu_sdk.models: Pydantic models for request/response payloads.azure_cu_sdk.helpers: Operational helper for document analysis and raw payload retrieval.azure_cu_sdk.client_async: Raw async REST client for the Content Understanding API.
Installation
pip install azure-cu-sdk
Quickstart (Async)
import asyncio
from azure_cu_sdk.aio import (
AsyncAzureContentUnderstandingClient,
ContentUnderstandingExecutionConfig,
ContentUnderstandingOperationsHelper,
DocumentExecutionRequest,
)
async def main() -> None:
async with AsyncAzureContentUnderstandingClient(
endpoint="https://example.cognitiveservices.azure.com",
api_key="...",
api_version="2025-05-01-preview",
) as client:
helper = ContentUnderstandingOperationsHelper(
client=client,
config=ContentUnderstandingExecutionConfig(analyzer_id="my-analyzer"),
)
payload = await helper.analyze_document(
DocumentExecutionRequest(
document_url="https://example.com/doc.pdf",
file_name="doc.pdf",
file_id="doc-001",
),
analyzer_id="override-analyzer",
)
print(payload)
asyncio.run(main())
Without a Context Manager
If you do not want to use async with, you must call await client.close() when done:
import asyncio
from azure_cu_sdk.aio import AsyncAzureContentUnderstandingClient
async def main() -> None:
client = AsyncAzureContentUnderstandingClient(
endpoint="https://example.cognitiveservices.azure.com",
api_key="...",
api_version="2025-05-01-preview",
)
try:
analyzers = await client.get_all_analyzers()
print(analyzers)
finally:
await client.close()
asyncio.run(main())
Package Layout
azure_cu_sdk/
aio/
__init__.py
client.py
client_async.py
exceptions.py
helpers.py
models.py
types.py
Async Client (azure_cu_sdk.client_async)
AsyncAzureContentUnderstandingClient
Construct the client with your Azure endpoint, API version, and auth. You can provide either an API key or a token provider.
If not provided, api_version defaults to 2025-05-01-preview.
client = AsyncAzureContentUnderstandingClient(
endpoint="https://example.cognitiveservices.azure.com",
api_version="2025-05-01-preview",
api_key="...",
)
Methods
-
get_all_analyzers() -> Dict[str, Any]- Returns a dictionary with a
valuelist of analyzers.
- Returns a dictionary with a
-
get_analyzer_detail_by_id(analyzer_id: str) -> Dict[str, Any]- Returns details for a specific analyzer.
-
begin_create_analyzer(analyzer_id: str, analyzer_schema: AnalyzerSchema) -> aiohttp.ClientResponse- Creates or updates an analyzer. Returns the raw HTTP response.
-
delete_analyzer(analyzer_id: str) -> aiohttp.ClientResponse- Deletes an analyzer.
-
begin_analyze_url(analyzer_id: str, url: str) -> aiohttp.ClientResponse- Submits an HTTP/HTTPS document URL for analysis.
-
begin_analyze_binary(analyzer_id: str, file_location: str) -> aiohttp.ClientResponse- Submits a local file for analysis.
-
poll_result(response: aiohttp.ClientResponse, timeout_seconds: int = 180, polling_interval_seconds: int = 2) -> Dict[str, Any]- Polls the operation until completion and returns the final payload.
-
get_result_file(analyze_response: aiohttp.ClientResponse, file_id: str) -> Optional[bytes]- Fetches a generated result file by ID.
-
begin_create_classifier(classifier_id: str, classifier_schema: ClassifierSchema) -> aiohttp.ClientResponse- Creates or updates a classifier.
-
begin_classify(classifier_id: str, file_location: str) -> aiohttp.ClientResponse- Classifies a document from a local path or public URL.
Notes
- The client lazily creates an
aiohttp.ClientSessionif you do not provide one. - Call
await client.close()if you did not useasync with.
Helper Layer (azure_cu_sdk.helpers)
ContentUnderstandingOperationsHelper
The helper wraps the async client and returns the raw service payload.
helper = ContentUnderstandingOperationsHelper(
client=client,
config=ContentUnderstandingExecutionConfig(analyzer_id="my-analyzer"),
)
analyze_document
payload = await helper.analyze_document(
DocumentExecutionRequest(
document_url="https://example.com/doc.pdf",
file_name="doc.pdf",
file_id="doc-001",
),
analyzer_id="override-analyzer",
)
To analyze a local file, pass file_path instead of document_url:
payload = await helper.analyze_document(
DocumentExecutionRequest(
file_path="C:/data/doc.pdf",
file_name="doc.pdf",
file_id="doc-001",
),
analyzer_id="override-analyzer",
)
- If
analyzer_idis passed, it overrides the default in the config. - Returns the raw Content Understanding response payload with no modifications.
- On failure, raises the underlying exception.
Analyzer Management
You can create or update analyzers using typed schemas.
from azure_cu_sdk.models import AnalyzerSchema
schema = AnalyzerSchema(
kind="document",
description="My analyzer",
)
resp = await helper.create_analyzer(
analyzer_id="my-analyzer",
analyzer_schema=schema,
)
print(resp)
DocumentExecutionRequest
document_url: HTTP/HTTPS URL of the document.file_name: Original file name.file_id: Stable identifier used in output chunk IDs.
ContentUnderstandingExecutionConfig
analyzer_id: Default analyzer for analysis calls.poll_timeout_seconds: Max time to wait for completion.poll_interval_seconds: Polling delay.
Raw Payload Handler
You can pass a handler to capture raw responses:
from azure_cu_sdk.helpers import default_raw_payload_logger
helper = ContentUnderstandingOperationsHelper(
client=client,
config=ContentUnderstandingExecutionConfig(analyzer_id="my-analyzer"),
raw_payload_handler=default_raw_payload_logger,
)
The handler signature is:
async def handler(payload: Dict[str, Any], request: DocumentExecutionRequest) -> None: ...
Models (azure_cu_sdk.models)
Pydantic models for payload shape. These are generic and not tied to a specific analyzer schema:
TextSourceDocumentSourceImageSourceContentItemAnalyzeRequestAnalyzeResponseAnalyzerSchemaClassifierSchema
Exceptions (azure_cu_sdk.exceptions)
AzureCUError: Base errorClientConfigurationError: Missing/invalid configAuthenticationError: Missing authServiceError: Non-2xx responses or service failures
Packaging
The project uses Hatchling and is ready for PyPI:
python -m build
python -m twine upload dist/*
CLI
Analyze a document URL:
azure-cu-sdk analyze --endpoint https://example.cognitiveservices.azure.com ^
--api-key YOUR_KEY ^
--analyzer-id my-analyzer ^
--file-name doc.pdf ^
--file-id doc-001 ^
--url https://example.com/doc.pdf
Analyze a local file:
azure-cu-sdk analyze --endpoint https://example.cognitiveservices.azure.com ^
--api-key YOUR_KEY ^
--analyzer-id my-analyzer ^
--file-name doc.pdf ^
--file-id doc-001 ^
--file C:/data/doc.pdf
Versioning
Set versions in pyproject.toml before publishing.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file azure_cu_sdk-0.1.2.tar.gz.
File metadata
- Download URL: azure_cu_sdk-0.1.2.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
741eb63b82bfa073330dbe8c518b590e4482772c92145d523c2c447e7d9ce491
|
|
| MD5 |
36e0700ba3f98bf6bdbb89c37ce93386
|
|
| BLAKE2b-256 |
73bf8fe167eb2e59610b4be65fac260b59b7d09467c936d6ac0395caec2f7943
|
File details
Details for the file azure_cu_sdk-0.1.2-py3-none-any.whl.
File metadata
- Download URL: azure_cu_sdk-0.1.2-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3e8369df563392d84af2fb85ad3239c6667cc703f53656d3d5a580102716bd1
|
|
| MD5 |
7f087f6eab11ea773d30f4f59e924f2b
|
|
| BLAKE2b-256 |
3987054cb6bdbdce49f91d78818a0f63df9cfd53096770f0d6be7589b0c54754
|