ImportError when importing consume_sync_iterator / consume_async_iterator from _streams
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
mainbranch)
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
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:
-
Verify the files are present
- In your virtual environment, open
…/site-packages/openai/_utils/_streams.pyand confirm thatconsume_sync_iteratorandconsume_async_iteratorare defined.
- In your virtual environment, open
-
Re-install using uv (recommended by the SDK)
-
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
I think your installation is broken somehow, this does not appear to be a bug in the SDK.