Documentation strings

A good convention is to append "__doc__" to the name of the object being documented to compose a good variable name.

Module documentation string

By far the easiest, add a character string argument to the end of Py_InitModule.
void
initmodname()
  {
    static char modname__doc__[] = "\
This module contains some functions, constants and maybe a type.";

    (void)Py_InitModule3("modname", methods, modname__doc__);
  }

Function documentation string

Add the character string as a fourth field in each entry of the PyMethodDef.
char MyCommand__doc__[] = "\
add(a, b)\n\
Add two numbers.";

PyMethodDef methods[] = {
  {"add", MyCommand, METH_VARARGS, MyCommand__doc__},
  {NULL, NULL},
};

Type documentation string

Add some addition fields to the PyTypeObject definition, to position the documentation string.
char counter__doc__[] = "\
counter([initval])\n\
An object which can be incremented or decremented.";

PyTypeObject counter_Type = {
  PyObject_HEAD_INIT(&PyType_Type)
  0,
  "counter",
  sizeof(counter),
  0,
  counter_dealloc,
  counter_print,
  counter_getattr,
  counter_setattr,
  counter_compare,
  counter_repr,
  &counter_as_number,
  0,
  0,
  counter_hash,
  0,
  counter_str,         /* tp_str */
  0,                   /* tp_getattro */
  0,                   /* tp_setattro */
  0,                   /* tp_as_buffer */
  0,                   /* tp_xxx4 */
  counter__doc__,      /* tp_doc */
};

Variable documentation strings

There is no support for attaching documentation strings to a variable or attribute.
Copyright (C) 1999 Michael P. Reilly, All rights reserved.
Written by Michael P. Reilly.