Skip to main content
ezpyinline

The ezpyinline is a pure python module which requires almost no setup to
allows you put C source code directly "inline" in a Python script or module,
then the C code is automatically compiled and then loaded for immediate access from Python.

ezpyinline is forked from PyInline (http://pyinline.sourceforge.net/)
but aim to be as easy as possible and do all the magics for you.

It's great for test usage, since it's requires almost no setup for ezpyinline.
Just grab ezpyinline.py into your program directory and start to use it.

The compiled python extension will placed at ~/.ezpyinline/ ,
however, you could easily change this via EZPYINLINE_ROOTDIR to any where you want.
Also you don't need to care recompile or older version function/files,
ezpyinline will auto remove older version functions which you no longer needed.

ezpyinline tested in python2.4+ on linux,
however it should works in python2.3+.
You'll need python-dev and working C compilers/toolchains to compile C.
However, if you just wanna deploy on non-develop environment,
just copy the ~/.ezpyinline directory and it should also works.

Tutorial:

Using ezpyinline is very simple: (also see example 1: helloworld.py )

1. write a C function and put this function in a raw string literal.
2. create a name binding use ezpyinline.C()
3. call your C function in python from where you need it.
4. run your python program as there's no C code inside it.

So grab ezpyinline.py and copy it to your current directory,
(or just use easy_install -Z ezpyinline if you have setuptools installed),
and try the following example.

Note: use raw string parameter in ezpyinline.C() will be a good practice.
This prevents problems caused from the escape characters in C string literal.

* Example 1: helloworld.py

--- cut-here ---

#!/usr/bin/python
import ezpyinline

#step 1
code = r"""
int helloworld() {
printf("hello ezpyinline!
");
}
"""
#step 2
ezc = ezpyinline.C(code)

#step 3
ezc.helloworld()

----------------
and step 4: type python helloworld.py in shell:

#python helloworld.py
hello ezpyinline!

program should works now, if you have any problem,
check if your C compiler and python-dev package installed.

You could also write like this:

* Example 1.b: helloworld2.py

--- cut-here ---

#!/usr/bin/python
import ezpyinline

ezc = ezpyinline.C(
r"""
int helloworld() {
printf("hello ezpyinline
");
}
""")

ezc.helloworld()

----------------

* Example 2: prime.py

--- cut-here ---

#!/usr/bin/python
import ezpyinline

ezc = ezpyinline.C(
r"""
int prime(int num) {
int x;
for (x = 2; x < (num - 1) ; x++) {
if (num == 2) {
return 1;
}
if (num % x == 0) {
return x;
}
}
return 1;
}
""")

for num in xrange(10000):
is_prime = ezc.prime(num)
if is_prime == 1:
print "%d is a prime number" % num
else:
print "%d equals %d * %d" %(num,is_prime,num/is_prime)

----------------
run time in my p4-3.0G box:

real 0m0.590s
user 0m0.430s
sys 0m0.020s

----------------
#!/usr/bin/python
for num in xrange(10000):
is_prime = 1
for x in xrange(2,num-1):
if (num % x == 0):
is_prime = x
break

if is_prime == 1:
print "%d is a prime number" % num
else:
print "%d equals %d * %d" %(num,is_prime,num/is_prime)

----------------
run time in my p4-3.0G box:

real 0m3.300s
user 0m3.190s
sys 0m0.090s

* Example 3: oldstyle_pyinline.py

PyInline compatibility, you old PyInline code still works!

As for now, most of code in ezpyinline was from PyInline,
everything you can do in PyInline should still works.

--- cut-here ---
#import PyInline
from ezpyinline import PyInline # only change PyInline import to this line

m = PyInline.build(code="""
double my_add(double a, double b) {
return a + b;
}
""", language="C")

print m.my_add(4.5, 5.5) # Should print out "10.0"
----------------

If you need more complex usage please also see PyInline's README
(http://pyinline.cvs.sourceforge.net/pyinline/PyInline/README.txt?revision=1.2&view=markup)
,distutils package (http://www.python.org/sigs/distutils-sig/)
,Python/C API Reference Manual (http://docs.python.org/api/api.html)
and Extending and Embedding the Python Interpreter (http://docs.python.org/ext/ext.html)

For more more complex usage, you should check:
Pyrex: http://www.cosc.canterbury.ac.nz/greg.ewing/python/Pyrex/
weave: http://www.scipy.org/Weave
and ShedSkin: http://sourceforge.net/projects/shedskin

Feedbacks are very welcome, please send them to my email.

Website: http://ezpyinline.sf.net

Author: __tim__ <timchen119.at.gmail.com>
License: The Artistic License (http://www.opensource.org/licenses/artistic-license.php)

Changelog:
2007-02-08 Version 0.1 public released.

Release files for ezpyinline 0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ezpyinline 0.1
File Size Uploaded
ezpyinline-0.1.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ezpyinline 0.1
File Interpreter ABI Platform
ezpyinline-0.1-py2.4.egg Legacy Egg format - - Details

Total release size:24.9 kB

Release files / ezpyinline-0.1.tar.gz

Download URL ezpyinline-0.1.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
615ce7a2f090ee225c0b2427615b2d6e9d7163cf4a1e13b67f25285d839f583a
BLAKE2b-256 checksum
How to use checksums
f802d6aaff6ff6846befa4c19726d3a414298bd9718232009ac332a3f51c22a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / ezpyinline-0.1-py2.4.egg

Download URL ezpyinline-0.1-py2.4.egg
Size 17.3 kB
Tags Egg
SHA-256 checksum
How to use checksums
5fb2e29abda20266207ab1ee91afeb600295a3e59620a5f150262de1c0347128
BLAKE2b-256 checksum
How to use checksums
5e381a09de29ef67ae1017f9fa6bf7e4af1c4553dbf9965aeb8e600f6a9a2a54
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page