title: How should I perform imports in a python module without polluting its namespace?
body: <p>I am developing a Python package for dealing with some scientific data. There are multiple frequently-used classes and functions from other modules and packages, including numpy, that I need in virtually every function defined in any module of the package.</p>
  
  <p>What would be the Pythonic way to deal with them? I have considered multiple variants, but every has its own drawbacks.</p>
  
  <ul>
  <li><p>Import the classes at module-level with <code>from foreignmodule import Class1, Class2, function1, function2</code><br>
  Then the imported functions and classes are easily accessible from every function. On the other hand, they pollute the module namespace making <code>dir(package.module)</code> and <code>help(package.module)</code> cluttered with imported functions</p></li>
  <li><p>Import the classes at function-level with <code>from foreignmodule import Class1, Class2, function1, function2</code><br>
  The functions and classes are easily accessible and do not pollute the module, but imports from up to a dozen modules in every function look as a lot of duplicate code.</p></li>
  <li><p>Import the modules at module-level with <code>import foreignmodule</code><br>
  Not too much pollution is compensated by the need to prepend the module name to every function or class call.</p></li>
  <li><p>Use some artificial workaround like using a function body for all these manipulations and returning only the objects to be exported... like this</p>
  
  <pre><code>def _export():
      from foreignmodule import Class1, Class2, function1, function2
      def myfunc(x):
          return function1(x, function2(x))
      return myfunc
  myfunc = _export()
  del _export
  </code></pre>
  
  <p>This manages to solve both problems, module namespace pollution and ease of use for functions... but it seems to be not Pythonic at all.</p></li>
  </ul>
  
  <p>So what solution is the most Pythonic? Is there another good solution I overlooked?</p>