A simple python module that acts as an interface for C code.
CC0-1.0 License
A simple python module template that acts as an interface for C/C++/Rust code.
It is specifically written and tested for Python 3.x, it does NOT work with Python 2.
Using this template as a basis for custom C/C++/Rust modules has the following advantages:
Before you create your own C modules, you can verify that your system is set up correctly by executing the test.py
script.
If everything is correct, you should see Hello, world!
and no error message.
To create your own C module, just copy and rename the helloWorldModule
folder to wherever you want your module to be.
Then, modify the __src
folder contents:
hello.h
and hello.c
.module.c
to include your function headers and add your functions to the methods
array.wrappers.py
.Before you create your own C++ modules, you can verify that your system is set up correctly by executing the testCpp.py
script.
If everything is correct, you should see Hello, world!
and no error message.
The C++ version needs the following Python libraries:
To create your own C++ module, just copy and rename the helloWorldCppModule
folder to wherever you want your module to be.
Then, modify the __src
folder contents:
hello.h
and hello.cpp
.module.cpp
to include your function headers and add your functions to the PYBIND11_MODULE definition.wrappers.py
.Before you create your own Rust modules, you can verify that your system is set up correctly by executing the testRust.py
script.
If everything is correct, you should see Hello, world!
and no error message.
The Rust version needs the following Python libraries:
Also, you need a Rust distribution that is compatible with pyo3. (pyo3 is now compatible with rust stable!)
To create your own Rust module, just copy and rename the helloWorldRustModule
folder to wherever you want your module to be.
Then, modify the __src
folder contents:
__lib
, though.wrappers.py
.For more information about how to write Rust code that interfaces with Python, read:
Operating System | C | C++ | Rust |
---|---|---|---|
Windows | ≥ 3.5 | ≥ 3.5 | -- |
Windows (x64) | ≥ 3.5 | ≥ 3.5 | ≥ 3.6 |
Linux | ≥ 3.5 | ≥ 3.5 | ≥ 3.5 |
Mac OS | ≥ 3.6 | ≥ 3.6 | ≥ 3.6 |