title: How to just import part of __init__.py?
body: <p>I have a package with some files and I'm having some importation issues.
  Let's say I have the following files: </p>
  
  <pre><code>main.py
  Lib
   ├─ __init__.py
   ├─ file1.py
   └─ file2.py
  </code></pre>
  
  <p><strong>main.py</strong>:</p>
  
  <pre><code>from Lib import ClassA
  
  foo = ClassA('anything')
  </code></pre>
  
  <p><strong>Lib/init.py</strong>:</p>
  
  <pre><code>from .file1 import ClassA
  from .file2 import ClassB
  </code></pre>
  
  <p><strong>file1.py</strong>:</p>
  
  <pre><code>import a_lot_of_things
  
  class ClassA:
    pass
  </code></pre>
  
  <p><strong>file2.py</strong>:</p>
  
  <pre><code>import a_lot_of_other_things
  
  class ClassB:
    pass
  </code></pre>
  
  <p>This code works, but Python will also import all the other classes in the file, as the ClassB. The problem is that Python takes a lot of time importing all the libraries of file2.py which I don't wanna use. </p>
  
  <p>I know it happens because Python is running init.py and it is importing all classes, even if I ask for just one. But I think it should do this only if I write:</p>
  
  <pre><code>from Lib import *
  </code></pre>
  
  <p>Is there a way to, inside init.py, check if I'm importing all or just one specific class to run just this file/importation?</p>
  
  <p>I also tried to structure my directory this way:</p>
  
  <pre><code>main.py
  Lib
   ├─ __init__.py
   ├─ ClassA
   │   ├─ __init__.py
   │   └─ file1.py
   └─ ClassB 
       ├─ __init__.py
       └─ file2.py
  </code></pre>
  
  <p>So I cleaned Lib/init.py and put the importations into each init.py.</p>
  
  <p><strong>ClassA/init.py</strong>:</p>
  
  <pre><code>from .file1 import ClassA
  </code></pre>
  
  <p><strong>ClassB/init.py</strong>:</p>
  
  <pre><code>from .file2 import ClassB
  </code></pre>
  
  <p>But now I need to use it this way:</p>
  
  <p><strong>main.py</strong>:</p>
  
  <pre><code>from Lib import ClassA
  
  foo = ClassA.ClassA('anything')
  </code></pre>
  
  <p>And I'd like to use it directly, as I wrote before. Is there a way to do this?</p>