title: What are good rules of thumb for Python imports?
body: <p>I am a little confused by the multitude of ways in which you can import modules in Python.  </p>
  
  <pre><code>import X
  import X as Y
  from A import B
  </code></pre>
  
  <p>I have been reading up about scoping and namespaces, but I would like some practical advice on what is the best strategy, under which circumstances and why.  Should imports happen at a module level or a method/function level?  In the <code>__init__.py</code> or in the module code itself?</p>
  
  <p>My question is not really answered by "<a href="https://stackoverflow.com/questions/45122/python-packages-import-by-class-not-file">Python packages - import by class, not file</a>" although it is obviously related.</p>