azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

ModuleNotFoundError: No module named 'aiohttp' when using async DocumentAnalysisClient

Open Kevv-J opened this issue 3 months ago • 4 comments

Package Name: azure-ai-formrecognizer

  • Package Version: 3.3.3
  • Operating System: Linux
  • Python Version: 3.10

Describe the bug When using the async version of DocumentAnalysisClient from azure.ai.formrecognizer.aio, the application fails with ModuleNotFoundError: No module named 'aiohttp' even though aiohttp is not listed as a dependency in the package metadata.

To Reproduce Steps to reproduce the behavior:

  1. Install azure-ai-formrecognizer==3.3.3 with only its declared dependencies
  2. Create a Python script with async DocumentAnalysisClient:
from azure.ai.formrecognizer.aio import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential

async def test_client():
    async with DocumentAnalysisClient(
        endpoint="https://example.cognitiveservices.azure.com/",
        credential=AzureKeyCredential("key")
    ) as client:
        pass
  1. Run the script
  2. Error occurs when trying to instantiate the async client

Expected behavior The async DocumentAnalysisClient should work without requiring manual installation of unlisted dependencies, or the package should clearly declare aiohttp as a dependency for async functionality.

Screenshots Full stack trace:

  File "referral_extraction/utils/ocr.py", line 61, in parse_document_standard
    async with DocumentAnalysisClient(
  File ".../azure/ai/formrecognizer/aio/_document_analysis_client_async.py", line 66, in __init__
    super().__init__(
  File ".../azure/ai/formrecognizer/aio/_form_base_client_async.py", line 79, in __init__
    self._client = FormRecognizer(
  File ".../azure/ai/formrecognizer/_generated/aio/_form_recognizer_client.py", line 99, in __init__
    self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)
  File ".../azure/core/_pipeline_client_async.py", line 166, in __init__
    self._pipeline = pipeline or self._build_pipeline(self._config, **kwargs)
  File ".../azure/core/_pipeline_client_async.py", line 260, in _build_pipeline
    from .pipeline.transport._aiohttp import AioHttpTransport
  File ".../azure/core/pipeline/transport/_aiohttp.py", line 45, in <module>
    import aiohttp
  ModuleNotFoundError: No module named 'aiohttp'

Additional context

  • Package metadata shows dependencies: azure-common, azure-core, msrest, typing-extensions (no aiohttp)
  • The async client internally uses azure-core's AioHttpTransport which requires aiohttp
  • Current workaround: manually install aiohttp
  • This affects runtime behavior and creates poor developer experience with unclear error messaging
  • Similar pattern may affect other Azure SDK packages with async support

Kevv-J avatar Sep 12 '25 20:09 Kevv-J

@vkurpad @yungshinlintw

github-actions[bot] avatar Sep 12 '25 20:09 github-actions[bot]

I am seeing the same error when invoking DefaultAzureCredential. Here are my installed versions of azure projects:

azure-core                             1.35.0
azure-core-tracing-opentelemetry       1.0.0b12
azure-cosmos                           4.9.0
azure-identity                         1.24.0
azure-monitor-opentelemetry            1.8.0
azure-monitor-opentelemetry-exporter   1.0.0b41
azure-storage-blob                     12.26.0

And here are my dependencies (among others) for pyproject.toml:

    "azure-cosmos>=4.9.0",
    "azure-identity>=1.24.0",
    "azure-storage-blob>=12.26.0",

jomalsan avatar Sep 23 '25 19:09 jomalsan

From https://learn.microsoft.com/en-us/python/api/overview/azure/ai-documentintelligence-readme?view=azure-python#examples

Image

You need to install aiohttp explicitly.

johnkntran avatar Nov 25 '25 11:11 johnkntran

Hi @Kevv-J. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

github-actions[bot] avatar Dec 11 '25 17:12 github-actions[bot]

Hi @Kevv-J, since you haven’t asked that we /unresolve the issue, we’ll close this out. If you believe further discussion is needed, please add a comment /unresolve to reopen the issue.

github-actions[bot] avatar Dec 18 '25 22:12 github-actions[bot]