and kwargsall of type pyobject *the self parameter is used when the wrapper function is implementing built-in method to be applied to an instance of some object in this casethe instance is placed in the self parameter otherwiseself is set to null args is tuple containing the function arguments passed by the interpreter kwargs is dictionary containing keyword arguments arguments are converted from python to using the pyarg_parsetuple(or pyarg_parsetupleandkeywords(function similarlythe py_buildvalue(function is used to construct an acceptable return value these functions are described in later sections documentation strings for extension functions should be placed in separate string variables such as py_gcd_doc and py_replace_doc as shown these variables are referenced during module initialization (described shortlywrapper functions should neverunder penalty of certain flaming deathmutate data received by reference from the interpreter this is why the py_replace(wrapper is making copy of the received string before passing it to the function (which modifies it in placeif this step is omittedthe wrapper function may violate python' string immutability if you want to raise an exceptionyou use the pyexc_setstring(function as shown in the py_distance(wrapper null is returned to signal that an error has occurred the method table _examplemethods is used to associate python names with the wrapper functions these are the names used to call the function from the interpreter the meth_varargs flag indicates the calling conventions for wrapper in this caseonly positional arguments in the form of tuple are accepted it can also be set to meth_varargs meth_keywords to indicate wrapper function accepting keyword arguments the method table additionally sets the documentation strings for each wrapper function the final part of an extension module performs an initialization procedure that varies between python and python in python the module initialization function init_example is used to initialize the contents of the module in this casethe py_initmodule("_example",_examplemethodsfunction creates module_exampleand populates it with built-in function objects corresponding to the functions listed in the method table for python you have to create an pymoduledef object _examplemodule that describes the module you then write function pyinit_ _example(that initializes the module as shown the module initialization function is also the place where you install constants and other parts of moduleif necessary for examplethe pymodule_addintmacro(is adding the value of preprocessor to the module it is important to note that naming is critically important for module initialization if you are creating module called modnamethe module initialization function must be called initmodname(in python and pyinit_modname(in python if you don' do thisthe interpreter won' be able to correctly load your module naming extension modules it is standard practice to name extension modules with leading underscore such as '_examplethis convention is followed by the python standard library itself for lib fl ff