openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

ImportError when importing consume_sync_iterator / consume_async_iterator from _streams

Open nandakrishnan1311 opened this issue 1 year ago • 2 comments

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • [x] This is an issue with the Python library

Describe the bug

Bug Report

Description

When trying to import consume_sync_iterator or consume_async_iterator from openai._utils._streams, the SDK raises an ImportError. This prevents running tests or using these utilities in client code.

Environment

  • OS: Windows 10
  • Python: 3.10.18
  • Repository: openai-python (cloned from main branch)

Minimal Reproduction

from openai._utils._streams import consume_sync_iterator

# Expected: function should import successfully
# Actual: raises ImportError


### To Reproduce

## To Reproduce
Steps to reproduce the behavior:

1. Clone the `openai-python` repository from GitHub:
   ```bash
   git clone https://github.com/openai/openai-python.git
   cd openai-python

2. Create and activate a virtual environment:
    ```bash
    python -m venv venv
    source venv/bin/activate   # macOS/Linux
    venv\Scripts\activate      # Windows

3. Install dependencies:
    ```bash
    pip install -r requirements-dev.lock
    from openai._utils._streams import consume_sync_iterator, consume_async_iterator

 4. Try importing the functions from _streams:
     ```bash
     from openai._utils._streams import consume_sync_iterator, consume_async_iterator

5. Observe the error:
    ```bash
    ImportError: cannot import name 'consume_sync_iterator' from 'openai._utils._streams'

6. Attempt to run the test file:
   ```bash
   pytest tests/test_streams_utils.py

You may see import errors preventing the tests from running.



### Code snippets

```Python

OS

Windows 10

Python version

Python: 3.10.18

Library version

openai v1.0.1

nandakrishnan1311 avatar Sep 21 '25 10:09 nandakrishnan1311

It looks like the functions do exist in the openai package, so the error is probably from an incomplete or incorrect install.

Please check the following:

  1. Verify the files are present

    • In your virtual environment, open …/site-packages/openai/_utils/_streams.py and confirm that consume_sync_iterator and consume_async_iterator are defined.
  2. Re-install using uv (recommended by the SDK)

  3. Make sure you’re running Python from the same venv where you installed the package.

After verifying the file and re-installing with uv, the import should work:

from openai._utils._streams import consume_sync_iterator, consume_async_iterator

AbdulSamad94 avatar Sep 22 '25 08:09 AbdulSamad94

I think your installation is broken somehow, this does not appear to be a bug in the SDK.

RobertCraigie avatar Sep 22 '25 09:09 RobertCraigie