Skip to main content

Calculates the deep size of Python's objects.

Project description

objsize

Calculates an object deep size.

This module uses python internal GC implementation to traverse all decedent objects. It ignores type objects (isinstance(o, type)) such as classes and modules as they are common among all objects. It is implemented without recursive calls for best performance.

Install

pip install objsize

Usage

from objsize import get_deep_size

my_data = (list(range(5)), list(range(10)))

class MyClass:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.d = {'x': x, 'y': y, 'self': self}

my_obj = MyClass(*my_data)

# Calculates my_obj deep size, including its stored data.
print(get_deep_size(my_obj))
# 1012

# Calculates my_obj deep size, ignoring non exclusive
# objects such as the ones stores in my_data.
print(get_deep_size(my_obj, only_exclusive=True))
# 408

License

GPL

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

objsize-0.2.1.tar.gz (16.5 kB view hashes)

Uploaded Source

Built Distribution

objsize-0.2.1-py2.py3-none-any.whl (3.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page