If you have cython installed, you can write
In [1]: import cython
In [2]: cython.inline("""
...: cdef int x = 2
...: print x
...: """)
Compiling /.../.cython/inline/_cython_inline_c02ff2feffdf73239d40335785cbb40b.pyx
because it changed.
Cythonizing /.../.cython/inline/_cython_inline_c02ff2feffdf73239d40335785cbb40b.pyx
2
There's also cython.compile, which compiles a method.
In [3]: @cython.compile
...: def foo(a, b, c):
...: return a + b * c
...:
In [4]: foo(1, 2, 3)
Compiling /.../.cython/inline/_cython_inline_1ca79cad3e887041fdcfd9b2023b4ab3.pyx
because it changed.
Cythonizing /.../.cython/inline/_cython_inline_1ca79cad3e887041fdcfd9b2023b4ab3.pyx
Out[4]: 7
In [5]: foo(1.1, 2, 3) # new input types
Compiling /.../.cython/inline/_cython_inline_5e9b3071b4d334ac6c7df73cef9e2edf.pyx
because it changed.
Cythonizing /.../.cython/inline/_cython_inline_5e9b3071b4d334ac6c7df73cef9e2edf.pyx
Out[5]: 7.1
In [6]: foo(1, 2, 3) # no re-compile
Out[6]: 7