Getting started with Heapy

Usage example

The following example shows

  1. How to create the session context: hp=hpy()
  2. How to use the interactive help: hp.doc, hp.doc.doc
  3. How to show the reachable objects in the heap: hp.heap()
  4. How to create and show a set of objects: hp.iso(1,[],{})
  5. How to show the shortest paths from the root to x: hp.iso(x).sp
>>> from guppy import hpy; hp=hpy()
>>> hp
Top level interface to Heapy.
Use eg: hp.doc for more info on hp.
>>> hp.doc
Top level interface to Heapy. Available attributes:
Anything            Rcs                 doc                 load
Clodo               Root                findex              monitor
Id                  Size                heap                pb
Idset               Type                heapu               setref
Module              Unity               idset               test
Nothing             Via                 iso
Use eg: hp.doc.<attribute> for info on <attribute>.
>>> hp.doc.doc
Overview documentation for top level Heapy object.
Provides a listing of the available attributes.
Accessing the attribute name on the doc objects gives further info, eg:

    >>> hp.doc.heap

gives doc for the heap method when hp is the top level Heapy object.

References may be embedded in the documentations. To access a
reference, opening up a web browser with the doc for it one can do eg:

    >>> hp.doc.heap[1]

The reference number 0 is special. If it is provided, it is the
reference to the html doc for the described object itself. So to see
in the web browser the doc for the heap method one can do:

    >>> hp.doc.heap[0]

References
    [0] heapy_Use.html#heapykinds.Use.doc
>>> hp.heap()
Partition of a set of 36,671 objects. Total size = 4,285,591 bytes.
 Index  Count   %      Size   % Cumulative   % Kind (class / dict of class)
     0 10,234  28   902,960  21    902,960  21 str
     1  8,964  24   727,944  17  1,630,904  38 tuple
     2  2,367   6   342,184   8  1,973,088  46 types.CodeType
     3  4,723  13   333,951   8  2,307,039  54 bytes
     4    435   1   333,064   8  2,640,103  62 type
     5  2,179   6   313,776   7  2,953,879  69 function
     6    435   1   245,640   6  3,199,519  75 dict of type
     7    502   1   193,376   5  3,392,895  79 dict (no owner)
     8     91   0   161,352   4  3,554,247  83 dict of module
     9  1,061   3    93,368   2  3,647,615  85 types.WrapperDescriptorType
<133 more rows. Type e.g. '_.more' to view.>
>>> hp.iso(1,[],{})
Partition of a set of 3 objects. Total size = 348 bytes.
 Index  Count   %     Size   % Cumulative   % Kind (class / dict of class)
     0      1  33      248  71        248  71 dict (no owner)
     1      1  33       72  21        320  92 list
     2      1  33       28   8        348 100 int
>>> x=[]
>>> hp.iso(x).sp
 0: hp.Root.i0_modules['__main__'].__dict__['x']
>>> 

Generated by GSL-HTML 3.2.0 on Sun Nov 15 00:16:00 2026