{"id":2141,"library":"objsize","title":"objsize","description":"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.","status":"active","version":"0.8.0","language":"python","source_language":"en","source_url":"https://github.com/liran-funaro/objsize","tags":["object-size","memory","deep-size","traversal","debugging","garbage-collection"],"install":[{"cmd":"pip install objsize","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.8 or newer.","package":"python","optional":false}],"imports":[{"note":"The primary function is `get_deep_size`.","symbol":"get_deep_size","correct":"from objsize import get_deep_size"}],"quickstart":{"code":"import objsize\n\nmy_data = {'name': 'Alice', 'age': 30, 'hobbies': ['reading', 'coding']}\ndeep_size_bytes = objsize.get_deep_size(my_data)\n\nprint(f\"The deep size of my_data is: {deep_size_bytes} bytes\")\n\nanother_obj = ['hello', 'world']\ntotal_deep_size = objsize.get_deep_size(my_data, another_obj)\nprint(f\"The deep size of multiple objects is: {total_deep_size} bytes\")","lang":"python","description":"Demonstrates how to calculate the deep size of a single object or multiple objects using `objsize.get_deep_size()`."},"warnings":[{"fix":"If you need to include sizes for specific shared objects or functions, you might need to implement a custom filter function (e.g., by modifying or replacing `objsize.traverse.shared_object_or_function_filter()`).","message":"By design, `objsize` attempts to ignore singletons (e.g., `None`) and type objects (classes, modules, functions, lambdas) when calculating deep size. This means they won't contribute to the reported size of the object's subtree, as they are considered shared.","severity":"gotcha","affected_versions":"All versions"},{"fix":"No fix needed; this is a design feature of `objsize` that enhances robustness. Simply be aware of the underlying traversal mechanism.","message":"Unlike some alternatives (e.g., Pympler), `objsize` uses a Breadth-First Search (BFS) approach internally to traverse object subtrees, avoiding recursive calls. This prevents hitting Python's default recursion depth limits, but users migrating from recursive deep-sizing tools should be aware of this architectural difference.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For such cases, the library allows users to supply custom methods for size calculation, referent identification, or object filtering to ensure accurate deep size measurement. Consult the library's documentation for details on custom handlers.","message":"For 'special objects' or objects with non-standard memory management (e.g., `weakref.proxy` or objects managing off-heap memory), `objsize`'s default calculation might not fully capture their size. You may need to provide custom handlers.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.8.0':54 'accur':46 'byte':21 'calcul':15 'collect':30,71 'common':36 'consumpt':19 'current':51 'debug':68 'deep':22,47,65 'deep-siz':64 'design':33 'function':7 'garbag':29,70 'garbage-collect':69 'gc':31 'general':56 'ignor':35 'implement':32 'infrequ':58 'intern':28 'leverag':25 'like':39 'memori':18,63 'object':11,38,43,61 'object-s':60 'objsiz':1,3 'packag':5 'provid':6 'python':4,26 'releas':59 'share':37 'singleton':40 'size':23,48,62,66 'subtre':13 'total':17 'travers':9,67 'type':42 'version':53","created_at":"2026-04-09T18:45:16.531087+00:00","updated_at":"2026-04-16T17:30:50.700449+00:00","problems":[{"fix":"Install the package using pip: `pip install objsize`","cause":"The `objsize` package has not been installed in your Python environment.","error":"ModuleNotFoundError: No module named 'objsize'"},{"fix":"Provide custom `get_size_func` and/or `get_referents_func` to `objsize.get_deep_size` to instruct it on how to correctly calculate the size or find referents for such objects. For example, for a `torch.Tensor` you might need to account for its underlying storage.","cause":"The `objsize` library, by default, might not fully traverse the internal memory structures of highly specialized objects (like those from NumPy or PyTorch) that manage their data outside of standard Python object references. This can lead to an underestimation of their 'deep size'.","error":"objsize returns an unexpectedly small or incorrect deep size for certain objects (e.g., torch.Tensor)"},{"fix":"Use the `objsize.get_deep_size()` function to calculate the memory consumption of an object: `import objsize; objsize.get_deep_size(my_object)`","cause":"You are attempting to access a non-existent attribute named 'size' directly on the `objsize` module. The primary function for calculating deep size is `get_deep_size`.","error":"AttributeError: module 'objsize' has no attribute 'size'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.8.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/liran-funaro/objsize","docs":null,"changelog":null,"pypi":"https://pypi.org/project/objsize/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-28","next_check":"2026-07-28","install_tag":null}}