objsize

0.8.0 · active · verified Thu Apr 09

The objsize Python package provides functionality for traversing an object's subtree and calculating its total memory consumption in bytes (deep size). It leverages Python's internal Garbage Collection (GC) implementation, designed to ignore commonly shared objects like singletons and type objects for more accurate deep sizing. It's currently in version 0.8.0 and generally has infrequent releases.

Warnings

Install

Imports

Quickstart

Demonstrates how to calculate the deep size of a single object or multiple objects using `objsize.get_deep_size()`.

import objsize

my_data = {'name': 'Alice', 'age': 30, 'hobbies': ['reading', 'coding']}
deep_size_bytes = objsize.get_deep_size(my_data)

print(f"The deep size of my_data is: {deep_size_bytes} bytes")

another_obj = ['hello', 'world']
total_deep_size = objsize.get_deep_size(my_data, another_obj)
print(f"The deep size of multiple objects is: {total_deep_size} bytes")

view raw JSON →