Suppose there is some well-known (third-party) Python package a
, which depends on another well-known package b
(e.g. imageio
and numpy
, respectively). Both are available through pip.
Now suppose my own code explicitly uses both a
and b
. Package versions are fixed in my requirements.txt
.
I see a few options for importing and using these packages, as described below. To me Options 2 and 3 look the cleanest, as they appear to reduce the number of dependencies that I need to manage explicitly.
Is there a preferred way of importing these packages, from the dependency management point-of-view? Or is it just a matter of style?
Option 1:
import a
import b
...
a.something()
b.something_else()
...
Option 2:
import a # which imports b
...
a.something()
a.b.something_else()
...
Option 3:
import a
from a import b
...
a.something()
b.something_else()
...
p.s. The following questions seem related but do not provide an answer: 1, 2, 3, 4