Text of docs.python.org › 3.12 › c-api › typeobj.html as Styx crawled it on Nov 20, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Type Object Structures — Python 3.12.16 documentation

Navigation index modules | next | previous | Python » 3.12.16 Documentation » Python/C API Reference Manual » Object Implementation Support » Type Object Structures | Theme | Type Object Structures ¶ Perhaps one of the most important structures of the Python object system is the structure that defines a new type: the PyTypeObject structure. Type objects can be handled using any of the PyObject_* or PyType_* functions, but do not offer much that’s interesting to most Python applications.

These objects are fundamental to how objects behave, so they are very important to the interpreter itself and to any extension module that implements new types. Type objects are fairly large compared to most of the standard types. The reason for the size is that each type object stores a large number of values, mostly C function pointers, each of which implements a small part of the type’s functionality. The fields of the type object are examined in detail in this section.

The fields will be described in the order in which they occur in the structure. In addition to the following quick reference, the Examples section provides at-a-glance insight into the meaning and use of PyTypeObject . Quick Reference ¶ “tp slots” ¶ PyTypeObject Slot [ 1 ] Type special methods/attrs Info [ 2 ] O T D I <R> tp_name const char * __name__ X X tp_basicsize Py_ssize_t X X X tp_itemsize Py_ssize_t X X tp_dealloc destructor X X X tp_vectorcall_offset Py_ssize_t X X ( tp_getattr ) getattrfunc __getattribute__, __getattr__ G ( tp_setattr ) setattrfunc __setattr__, __delattr__ G tp_as_async PyAsyncMethods * sub-slots % tp_repr reprfunc __repr__ X X X tp_as_number PyNumberMethods * sub-slots % tp_as_sequence PySequenceMethods * sub-slots % tp_as_mapping PyMappingMethods * sub-slots % tp_hash hashfunc __hash__ X G tp_call ternaryfunc __call__ X X tp_str reprfunc __str__ X X tp_getattro getattrofunc __getattribute__, __getattr__ X X G tp_setattro setattrofunc __setattr__, __delattr__ X X G tp_as_buffer PyBufferProcs * % tp_flags unsigned long X X ? tp_doc const char * __doc__ X X tp_traverse traverseproc X G tp_clear inquiry X G tp_richcompare richcmpfunc __lt__, __le__, __eq__, __ne__, __gt__, __ge__ X G ( tp_weaklistoffset ) Py_ssize_t X ? tp_iter getiterfunc __iter__ X tp_iternext iternextfunc __next__ X tp_methods PyMethodDef [] X X tp_members PyMemberDef [] X tp_getset PyGetSetDef [] X X tp_base PyTypeObject * __base__ X tp_dict PyObject * __dict__ ? tp_descr_get descrgetfunc __get__ X tp_descr_set descrsetfunc __set__, __delete__ X ( tp_dictoffset ) Py_ssize_t X ? tp_init initproc __init__ X X X tp_alloc allocfunc X ? ? tp_new newfunc __new__ X X ? ? tp_free freefunc X X ? ? tp_is_gc inquiry X X < tp_bases > PyObject * __bases__ ~ < tp_mro > PyObject * __mro__ ~ [ tp_cache ] PyObject * [ tp_subclasses ] void * __subclasses__ [ tp_weaklist ] PyObject * ( tp_del ) destructor [ tp_version_tag ] unsigned int tp_finalize destructor __del__ X tp_vectorcall vectorcallfunc [ tp_watched ] unsigned char sub-slots ¶ Slot Type special methods am_await unaryfunc __await__ am_aiter unaryfunc __aiter__ am_anext unaryfunc __anext__ am_send sendfunc nb_add binaryfunc __add__ __radd__ nb_inplace_add binaryfunc __iadd__ nb_subtract binaryfunc __sub__ __rsub__ nb_inplace_subtract binaryfunc __isub__ nb_multiply binaryfunc __mul__ __rmul__ nb_inplace_multiply binaryfunc __imul__ nb_remainder binaryfunc __mod__ __rmod__ nb_inplace_remainder binaryfunc __imod__ nb_divmod binaryfunc __divmod__ __rdivmod__ nb_power ternaryfunc __pow__ __rpow__ nb_inplace_power ternaryfunc __ipow__ nb_negative unaryfunc __neg__ nb_positive unaryfunc __pos__ nb_absolute unaryfunc __abs__ nb_bool inquiry __bool__ nb_invert unaryfunc __invert__ nb_lshift binaryfunc __lshift__ __rlshift__ nb_inplace_lshift binaryfunc __ilshift__ nb_rshift binaryfunc __rshift__ __rrshift__ nb_inplace_rshift binaryfunc __irshift__ nb_and binaryfunc __and__ __rand__ nb_inplace_and binaryfunc __iand__ nb_xor binaryfunc __xor__ __rxor__ nb_inplace_xor binaryfunc __ixor__ nb_or binaryfunc __or__ __ror__ nb_inplace_or binaryfunc __ior__ nb_int unaryfunc __int__ nb_reserved void * nb_float unaryfunc __float__ nb_floor_divide binaryfunc __floordiv__ nb_inplace_floor_divide binaryfunc __ifloordiv__ nb_true_divide binaryfunc __truediv__ nb_inplace_true_divide binaryfunc __itruediv__ nb_index unaryfunc __index__ nb_matrix_multiply binaryfunc __matmul__ __rmatmul__ nb_inplace_matrix_multiply binaryfunc __imatmul__ mp_length lenfunc __len__ mp_subscript binaryfunc __getitem__ mp_ass_subscript objobjargproc __setitem__, __delitem__ sq_length lenfunc __len__ sq_concat binaryfunc __add__ sq_repeat ssizeargfunc __mul__ sq_item ssizeargfunc __getitem__ sq_ass_item ssizeobjargproc __setitem__ __delitem__ sq_contains objobjproc __contains__ sq_inplace_concat binaryfunc __iadd__ sq_inplace_repeat ssizeargfunc __imul__ bf_getbuffer getbufferproc() bf_releasebuffer releasebufferproc() slot typedefs ¶ typedef Parameter Types Return Type allocfunc PyTypeObject * Py_ssize_t PyObject * destructor PyObject * void freefunc void * void traverseproc PyObject * visitproc void * int newfunc PyTypeObject * PyObject * PyObject * PyObject * initproc PyObject * PyObject * PyObject * int reprfunc PyObject * PyObject * getattrfunc PyObject * const char * PyObject * setattrfunc PyObject * const char * PyObject * int getattrofunc PyObject * PyObject * PyObject * setattrofunc PyObject * PyObject * PyObject * int descrgetfunc PyObject * PyObject * PyObject * PyObject * descrsetfunc PyObject * PyObject * PyObject * int hashfunc PyObject * Py_hash_t richcmpfunc PyObject * PyObject * int PyObject * getiterfunc PyObject * PyObject * iternextfunc PyObject * PyObject * lenfunc PyObject * Py_ssize_t getbufferproc PyObject * Py_buffer * int int releasebufferproc PyObject * Py_buffer * void inquiry PyObject * int unaryfunc PyObject * PyObject * binaryfunc PyObject * PyObject * PyObject * ternaryfunc PyObject * PyObject * PyObject * PyObject * ssizeargfunc PyObject * Py_ssize_t PyObject * ssizeobjargproc PyObject * Py_ssize_t PyObject * int objobjproc PyObject * PyObject * int objobjargproc PyObject * PyObject * PyObject * int See Slot Type typedefs below for more detail.

PyTypeObject Definition ¶ The structure definition for PyTypeObject can be found in Include/cpython/object.h . For convenience of reference, this repeats the definition found there: typedef struct _typeobject { PyObject_VAR_HEAD const char * tp_name ; /* For printing, in format "<module>.<name>" */ Py_ssize_t tp_basicsize , tp_itemsize ; /* For allocation */ /* Methods to implement standard operations */ destructor tp_dealloc ; Py_ssize_t tp_vectorcall_offset ; getattrfunc tp_getattr ; setattrfunc tp_setattr ; PyAsyncMethods * tp_as_async ; /* formerly known as tp_compare (Python 2) or tp_reserved (Python 3) */ reprfunc tp_repr ; /* Method suites for standard classes */ PyNumberMethods * tp_as_number ; PySequenceMethods * tp_as_sequence ; PyMappingMethods * tp_as_mapping ; /* More standard operations (here for binary compatibility) */ hashfunc tp_hash ; ternaryfunc tp_call ; reprfunc tp_str ; getattrofunc tp_getattro ; setattrofunc tp_setattro ; /* Functions to access object as input/output buffer */ PyBufferProcs * tp_as_buffer ; /* Flags to define presence of optional/expanded features */ unsigned long tp_flags ; const char * tp_doc ; /* Documentation string */ /* Assigned meaning in release 2.0 */ /* call function for all accessible objects */ traverseproc tp_traverse ; /* delete references to contained objects */ inquiry tp_clear ; /* Assigned meaning in release 2.1 */ /* rich comparisons */ richcmpfunc tp_richcompare ; /* weak reference enabler */ Py_ssize_t tp_weaklistoffset ; /* Iterators */ getiterfunc tp_iter ; iternextfunc tp_iternext ; /* Attribute descriptor and subclassing stuff */ struct PyMethodDef * tp_methods ; struct PyMemberDef * tp_members ; struct PyGetSetDef * tp_getset ; // Strong reference on a

The rest of this page is on the live site.