title: Cython code inside Python code
body: <p>There are several ways of using Cython with Python.</p>
  
  <ul>
  <li><p>First version (standard): you write your Cython code <code>mylib.pyx</code>, then you run this <code>setup.py</code>:</p>
  
  <p><code>from distutils.core import setup</code><br>
  <code>from Cython.Build import cythonize</code><br>
  <code>setup(ext_modules = cythonize("mylib.pyx"))</code></p>
  
  <p>that compiles it into a <code>.pyd</code> file, and then, in the main <code>myprogram.py</code>, you do <code>import mylib</code>.</p>
  
  <p>That's the standard way of working with Cython.</p></li>
  <li><p>Second version (<em>"on the fly compiling, with <code>pyximport</code>"</em>) :</p>
  
  <p>You write <code>mylib.pyx</code>, and you <strong>don't need</strong> any setup.py, you just do this in the main Python code:</p>
  
  <p><code>import pyximport; pyximport.install()</code><br>
  <code>import mylib</code></p>
  
  <p>That's it! The compilation will be done on the fly on the startup of the Python program!</p></li>
  </ul>
  
  <h1>Question:</h1>
  
  <p>Is there a "third version" (<em>"easier on the fly compiling"</em>):</p>
  
  <pre><code># myprogram.py
  
  import pyximport
  pyximport.compile("""
        # Here is directly the Cython code inserted in the main Python code
        def mycythonfunction(int a, int b):
            cdef int i, j, 
        ...
        """)
  
  res = mycythonfunction(3, 2)
  </code></pre>
  
  <p>i.e. with the Cython code directly inserted in the main Python code?</p>