Run some command that initializes your codebase, e.g. for a Django project do:
time python -X importtime manage.py --version 2> importtimes.txt
Visualize and analyse contents of importtimes.txt
with: https://kmichel.github.io/python-importtime-graph/
Defer imports by moving them inside functions/methods. With Python 3.12+ we can also mark imports as lazy like lazy import xyz
within the top level module scope, neat.
With deferring the largest/slowest few imports the startup time for any python commands can easily be halved or more, making everything noticeably faster!