title: Why should I use __all__ in __init__ of python package?
body: <p>I've already read <a href="https://stackoverflow.com/questions/44834/can-someone-explain-all-in-python">Can someone explain __all__ in Python?</a> and I understand that it only affects <code>from ... import *</code> statements, but I can't figure out a real use case. Why should I repeat exported names in <code>__all__</code> (DRY!) when I could simply avoid importing those names in <code>__init__</code> namespace?</p>
  
  <p>Example:</p>
  
  <p><code>mypackage/__init__.py</code></p>
  
  <pre><code>from a import A
  </code></pre>
  
  <p><code>mypackage/a.py</code></p>
  
  <pre><code>A = "A"
  A1 = "A1"
  </code></pre>
  
  <p><code>mypackage/b.py</code></p>
  
  <pre><code>B = "B"    
  </code></pre>
  
  <p>And then in python:</p>
  
  <pre><code>&gt;&gt;&gt; from mypackage import *
  &gt;&gt;&gt; A
  'A'
  &gt;&gt;&gt; 
  &gt;&gt;&gt; A1
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  NameError: name 'A1' is not defined
  &gt;&gt;&gt; b
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  NameError: name 'b' is not defined
  </code></pre>
  
  <p>As you can see <code>A</code> is in the namespace but <code>A1</code> and <code>b</code> are not. Why should I have to define <code>__all__ = ["A"]</code>?</p>