Search code examples
pythonccpython

Python compiled module documentation


I'm writing a library for Python in C compiled into a python module and I have managed to get it working just fine, however the IDE doesn't detect any documentation and what functions actually are contained in the module. How do I make that happen? The documentation doesn't mention that at all. Here's how i create the PyModuleDef struct:

PyDoc_STRVAR(parseFASTAdoc,
"parseFASTA(rawData:str) -> list[dict]\n\n"
"Returns a list of dicts containing FASTA data.");

PyDoc_STRVAR(parseGTFdoc,
"parseGTF(rawData:str) -> list[dict]\n\n"
"Returns a list of dicts containing GTF line data.");

static PyMethodDef eccLibMethods[] = {
    {"parseFASTA",  parseFasta, METH_VARARGS,
      parseFASTAdoc},
     {"parseGTF",  parseGTF, METH_VARARGS,
     parseGTFdoc},
    {NULL}       /* Sentinel */
};

static struct PyModuleDef eccLibModule = {
    PyModuleDef_HEAD_INIT,
    "eccLib",   /* name of module */
    NULL, /* module documentation, may be NULL */
    -1,
    eccLibMethods
};

PyMODINIT_FUNC PyInit_eccLib(void)
{
    return PyModule_Create(&eccLibModule);
}

Solution

  • After help from @Brian I managed to figure it out. Documentation in your C file is internal and won't be picked up by most IDEs. You need to create a .pyi file that functions similar to header files. They should be located in the library directory next to the .pyd file and .py file. There are utilities like mypy that can automaticly generate a .pyi file for you.