objsize

Traversal over Python’s objects subtree and calculating the total size of the subtree (deep size).

Sub Modules

objsize.traverse

Handling of traversal.

Classes and Functions

default_settings = <objsize.traverse.ObjSizeSettings object>

The default instance obj objsize settings. It can be updated to modify the default behaviour of objsize.

traverse_bfs(*objs, exclude=None, marked_set=None, exclude_set=None, get_referents_func=None, filter_func=None, exclude_modules_globals=None)[source]

Traverse all the arguments’ subtree. By default, this excludes shared objects, i.e., types, modules, functions, and lambdas.

Parameters:
Yields:

object – The traversed objects, one by one.

Return type:

Iterator[Any]

traverse_exclusive_bfs(*objs, exclude=None, marked_set=None, exclude_set=None, get_referents_func=None, filter_func=None, exclude_modules_globals=None)[source]

Traverse all the arguments’ subtree, excluding non-exclusive objects. That is, objects that are referenced by objects that are not in this subtree.

Parameters:
Yields:

object – The traversed objects, one by one.

Return type:

Iterator[Any]

See also

traverse_bfs

to understand which objects are traversed.

get_deep_size(*objs, exclude=None, marked_set=None, exclude_set=None, get_size_func=None, get_referents_func=None, filter_func=None, exclude_modules_globals=None)[source]

Calculates the deep size of all the arguments.

Parameters:
Returns:

The objects’ deep size in bytes.

Return type:

int

See also

traverse_bfs

to understand which objects are traversed.

get_exclusive_deep_size(*objs, exclude=None, marked_set=None, exclude_set=None, get_size_func=None, get_referents_func=None, filter_func=None, exclude_modules_globals=None)[source]

Calculates the deep size of all the arguments, excluding non-exclusive objects.

Parameters:
Returns:

The objects’ deep size in bytes.

Return type:

int

See also

traverse_exclusive_bfs

to understand which objects are traversed.

get_exclude_set(exclude=None, exclude_set=None, get_referents_func=<built-in function get_referents>, filter_func=<function shared_object_or_function_filter>, exclude_modules_globals=False)[source]

Traverse all the arguments’ subtree without ingesting the result, just to update the exclude_set. See traverse_bfs() for more information.

Deprecated:

It will be removed on version 1.0.0.

Parameters:
Returns:

The updated exclude-set.

Return type:

set

Attention

Deprecated. It will be removed on version 1.0.0.