PyErr_WarnEx(PyExc_DeprecationWarning, "foo deprecated. use fuzz", 1); But where can I write this? With Py_InitModule4 I can just pass a list of functions but no real execution part which is executed when a module is imported.