Speed up startup time by avoiding CLI import #3523
Unanswered
natehardison
asked this question in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Importing the
_main.py
module inhttpx/__init__.py
adds 0.087s worth of import time on my machine (MacBook M1 Pro, 32 GB RAM, macOS 15.3.1) running Python 3.13.2.It's certainly not a huge amount of time in the absolute, but it roughly doubles the amount of time it takes to
import httpx
, even when you're not intending to run the CLI. Here's an import time graph generated using tuna on the output ofpython -X importtime -c "import httpx" > import.log
A possible fix is to add
httpx/__main__.py
that does the import instead. This would also allowpython -m httpx
as in #3216. I did a quick proof of concept here: master...natehardison:httpx:masterIt does change the public API:
httpx.main
becomes the (more ungainly)httpx.__main__.main
.Beta Was this translation helpful? Give feedback.
All reactions