title: How are Python modules (which are shared libraries) imported without a .py file?
body: <p>I am running an interactive Python shell and trying to see the path from which a module is being imported using the 'inspect' module. The modules I am trying to import have Python wrappers around C++ APIs using SWIG. </p>
  
  <p>The following snippet shows my steps :</p>
  
  <pre><code>&gt;&gt;&gt; import os
  &gt;&gt;&gt; import inspect
  &gt;&gt;&gt;      
  &gt;&gt;&gt; import db
  &gt;&gt;&gt; inspect.getfile(db)
  'mypath1/lib/db/db.pyc'
  &gt;&gt;&gt;
  &gt;&gt;&gt; import dart
  &gt;&gt;&gt; inspect.getfile(dart)
  'mypath2/lib/dart.so'
  &gt;&gt;&gt;
  </code></pre>
  
  <p>My <code>PYTHONPATH</code> contains both <code>mypath1/lib/db</code>  and <code>mypath2/lib</code>.</p>
  
  <p>I was under the impression that in order to be able to load modules, the interpreter needs access to a <code>.py</code> file which then calls <code>imp.load_module</code> to load the required shared library (<code>.so</code> file). This is what I see in case of the <code>db</code> module which has a <code>db.py</code> file under <code>mypath1/lib/db</code>. However, <code>dart</code> does not have a <code>.py</code> file under <code>mypath2/lib</code>.</p>
  
  <p>Is it possible to import a module without the .py file as is happening in the case of the <code>dart</code> module ?</p>