title: Get package of Python object
body: <p>Given an object or type I can get the object's module using the <code>inspect</code> package</p>
  
  <h3>Example</h3>
  
  <p>Here, given a function I get the module that contains that function:</p>
  
  <pre><code>&gt;&gt;&gt; inspect.getmodule(np.memmap)
  &lt;module 'numpy.core.memmap' from ...&gt;
  </code></pre>
  
  <p>However what I really want is to get the top-level module that corresponds to the package, in this case <code>numpy</code> rather than <code>numpy.core.memmap</code>.</p>
  
  <pre><code>&gt;&gt;&gt; function_that_I_want(np.memmap)
  &lt;module 'numpy' from ...&gt;
  </code></pre>
  
  <p><em>Given an object or a module, how do I get the top-level module?</em></p>