objsize
Traversal over Python’s objects subtree and calculating the total size of the subtree (deep size).
Sub Modules
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:
objs (object(s)) – One or more object(s).
exclude (Iterable[Any] | None) – See
ObjSizeSettings
.marked_set (Set[int] | None) – See
TraversalContext
.exclude_set (Set[int] | None) – See
TraversalContext
.get_referents_func (Callable[[...], Iterable[Any]] | None) – See
ObjSizeSettings
.filter_func (Callable[[Any], bool] | None) – See
ObjSizeSettings
.exclude_modules_globals (bool | None) – See
ObjSizeSettings
.
- Yields:
object – The traversed objects, one by one.
- Return type:
- 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:
objs (object(s)) – One or more object(s).
exclude (Iterable[Any] | None) – See
ObjSizeSettings
.marked_set (Set[int] | None) – See
TraversalContext
.exclude_set (Set[int] | None) – See
TraversalContext
.get_referents_func (Callable[[...], Iterable[Any]] | None) – See
ObjSizeSettings
.filter_func (Callable[[Any], bool] | None) – See
ObjSizeSettings
.exclude_modules_globals (bool | None) – See
ObjSizeSettings
.
- Yields:
object – The traversed objects, one by one.
- Return type:
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:
objs (object(s)) – One or more object(s).
exclude (Iterable[Any] | None) – See
ObjSizeSettings
.marked_set (Set[int] | None) – See
TraversalContext
.exclude_set (Set[int] | None) – See
TraversalContext
.get_size_func (Callable[[Any], int] | None) – See
ObjSizeSettings
.get_referents_func (Callable[[...], Iterable[Any]] | None) – See
ObjSizeSettings
.filter_func (Callable[[Any], bool] | None) – See
ObjSizeSettings
.exclude_modules_globals (bool | None) – See
ObjSizeSettings
.
- Returns:
The objects’ deep size in bytes.
- Return type:
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:
objs (object(s)) – One or more object(s).
exclude (Iterable[Any] | None) – See
ObjSizeSettings
.marked_set (Set[int] | None) – See
TraversalContext
.exclude_set (Set[int] | None) – See
TraversalContext
.get_size_func (Callable[[Any], int] | None) – See
ObjSizeSettings
.get_referents_func (Callable[[...], Iterable[Any]] | None) – See
ObjSizeSettings
.filter_func (Callable[[Any], bool] | None) – See
ObjSizeSettings
.exclude_modules_globals (bool | None) – See
ObjSizeSettings
.
- Returns:
The objects’ deep size in bytes.
- Return type:
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:
exclude_set (Set[int] | None) – See
TraversalContext
.get_referents_func (Callable[[...], Iterable[Any]]) – See
ObjSizeSettings
.filter_func (Callable[[Any], bool]) – See
ObjSizeSettings
.exclude_modules_globals (bool) – See
ObjSizeSettings
.
- Returns:
The updated exclude-set.
- Return type:
Attention
Deprecated. It will be removed on version 1.0.0.