extending and embedding python instancethere are modules named _socket_thread_sreand _fileio corresponding to the programming components of the socketthreadingreand io modules generallyyou do not use these extension modules directly insteadyou create high-level python module such as the followingexample py from _example import add additional support code below the purpose of this python wrapper is to supply additional support code for your module or to provide higher-level interface in many casesit is easier to implement parts of an extension module in python instead of this design makes it easy to do this if you look at many standard library modulesyou will find that they have been implemented as mix of and python in this manner compiling and packaging extensions the preferred mechanism for compiling and packaging an extension module is to use distutils to do thisyou create setup py file that looks like thissetup py from distutils core import setupextension setup(name="example"version=" "py_modules ['example py']ext_modules extension("_example"["pyexample ","example "]in this fileyou need to include the high-level python file (example pyand the source files making up the extension module (pyexample cexample cto build the module for testingtype the followingpython setup py build_ext --inplace this will compile the extension code into shared library and leave it in the current working directory the name of this library will be _examplemodule so_examplemodule pydor some similar variant if the compilation was successfulusing your module is straightforward for examplepython python ( : dec : : [gcc (apple inc build )on darwin type "help""copyright""creditsor "licensefor more information import example example gcd( , example replace("hello world",','-'( 'hello-world'example distance(traceback (most recent call last)file ""line in notimplementederrordistance(not implemented lib fl ff