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

Slow import times

Open serozhenka opened this issue 1 year ago • 4 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

On average, it takes nearly 0.5 seconds to just import openai.

That may sound normal, but consider the case where a bunch of deps are imported and each one of them takes 0.5 seconds to be imported. Startup times of such an application go crazy.

To Reproduce

import time

start = time.time()
import openai

print(time.time() - start)

Alternatively, run:

python -X importtime -c "import openai"

Code snippets


OS

macOS

Python version

3.11.9

Library version

1.75.0

serozhenka avatar May 03 '25 14:05 serozhenka

@serozhenka can you try the latest changes in https://github.com/openai/openai-python/pull/2340?

pip install git+https://github.com/openai/openai-python.git@next

RobertCraigie avatar May 06 '25 12:05 RobertCraigie

@RobertCraigie Yeah, much better, down to .25s on average. Appreciate the work on the lazy imports. I think it can still be further improved by not trying to import from all of the modules in root __init__.py, but this would affect too many people to even be discussed, I guess.

serozhenka avatar May 06 '25 12:05 serozhenka

Yeah I think we're at the limit for what we can improve right now without sweeping breaking changes unfortunately.

RobertCraigie avatar Jun 09 '25 18:06 RobertCraigie

Created a similar bug, likely with a different cause but similar symptoms: 2819

jmathes avatar Jan 12 '26 18:01 jmathes