Module Objects

PyTypeObject PyModule_Type
Part of the Stable ABI.

This instance of PyTypeObject represents the Python module type. This is exposed to Python programs as types.ModuleType.

int PyModule_Check(PyObject *p)

Return true if p is a module object, or a subtype of a module object. This function always succeeds.

int PyModule_CheckExact(PyObject *p)

Return true if p is a module object, but not a subtype of PyModule_Type. This function always succeeds.

PyObject *PyModule_NewObject(PyObject *name)
Return value: New reference. Part of the Stable ABI since version 3.7.

Return a new module object with module.__name__ set to name. The module’s __name__, __doc__, __package__ and __loader__ attributes are filled in (all but __name__ are set to None). The caller is responsible for setting a __file__ attribute.

Return NULL with an exception set on error.

Added in version 3.3.

Changed in version 3.4: __package__ and __loader__ are now set to None.

PyObject *PyModule_New(const char *name)
Return value: New reference. Part of the Stable ABI.

Similar to PyModule_NewObject(), but the name is a UTF-8 encoded string instead of a Unicode object.

PyObject *PyModule_GetDict(PyObject *module)
Return value: Borrowed reference. Part of the Stable ABI.

Return the dictionary object that implements module’s namespace; this object is the same as the __dict__ attribute of the module object. If module is not a module object (or a subtype of a module object), SystemError is raised and NULL is returned.

It is recommended extensions use other PyModule_* and PyObject_* functions rather than directly manipulate a module’s __dict__.