title: Exposing a C++ class instance to a python embedded interpreter
body: <p>I am looking for a simple way to expose a C++ class instance to a python embedded interpreter.</p>
  <ul>
  <li>I have a C++ library. This library is wrapped (using swig for the moment) and I am able to use it from the python interpreter</li>
  <li>I have a C++ main program which instanciates a Foo class from my library and embeds a python interpreter</li>
  </ul>
  <p>I would like to expose my C++ world instance of Foo to the python world (and seen as a Foo class).</p>
  <p><strong>Is this possible, if so, how?</strong></p>
  <p>I think it's almost like in the first answer of :
  <a href="https://stackoverflow.com/questions/5055443/boost-python-how-to-pass-a-c-class-instance-to-a-python-class">boost::python::ptr or PyInstance_New usage</a></p>
  <p><strong>I guess this means I should use <code>boost.Python</code> to wrap my library?</strong></p>
  <p>My only goal is to manipulate my C++ instance of Foo in the embedded python interpreter (not sure that it can be done with the previous method).</p>
  <p>In fact, I already have exposed my Foo class to python (with swig).</p>
  <p><strong>What I have:</strong></p>
  <p><em>my Foo class:</em></p>
  <pre><code>class Foo{...};
  </code></pre>
  <p><em>my wrapped library (including the Foo class) exposed to python:</em> so I can start the python interpreter and do something like this :</p>
  <pre><code>import my_module
  foo=my_modulde.Foo()
  </code></pre>
  <p><strong>What I want:</strong></p>
  <p>Having a C++ main program which embeds a python interpreter and manipulates C++ world variables.</p>
  <pre><code>int main(int argc, char **argv)
  {
      Foo  foo;   // instanciates foo
      
      Py_Initialize();
  
      Py_Main(argc, argv); // starts the python interpreter
                           // and manipulates THE foo instance in it
  
      Py_Finalize();
      
      return 0;
  }
  </code></pre>