--- id: objsize version: "0.8.0" license: BSD-3-Clause license_treatment: permissive maintenance: aging --- # objsize — Traversal over Python's objects subtree and calculate the total size of the subtree in bytes (deep size). License: permissive · Maintenance: aging · Downloads: 3.0M/mo ## What it is and what it does objsize is a Python library that calculates how much memory an object and all its nested children consume, measured in bytes. It uses Python's garbage collection mechanism to traverse object graphs without recursive calls, making it faster and safer than naive approaches. The package automatically filters out shared objects like None, types, modules, classes, and functions, since these are typically shared across many instances and shouldn't be counted multiple times. You can measure single objects, multiple objects at once, or exclude specific subtrees from the calculation. The library offers customization hooks: you can define your own size calculation, referent discovery, and filtering logic to handle special cases like torch tensors or weakref proxies that don't expose their memory through Python's standard introspection. It also provides a traversal API to walk the entire object graph yourself. Use it for: - Debug memory leaks by measuring which objects and their children are consuming unexpected amounts of memory. - Profile data structure efficiency by comparing deep sizes of different implementations to find the most memory-efficient design. - Monitor memory usage in long-running applications by periodically checking the size of key objects to detect gradual bloat. - Analyze neural network models (e.g., torch tensors) by providing custom size handlers for framework-specific object types. - Validate that cached or pooled objects aren't growing unexpectedly by comparing their sizes across application lifecycle. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Measures the complete memory footprint of Python objects including their nested children, using garbage collection to traverse object graphs and calculate deep size in bytes. Yes. objsize is a straightforward, dependency-free memory profiling tool with no known vulnerabilities, permissive licensing, and broad Python version support. Install it if you need to measure object memory consumption beyond what sys.getsizeof() provides. The aging maintenance status is not a blocker for a stable utility library, but check the documentation to confirm it handles your Python version and object types. ## Install pip install objsize uv add objsize poetry add objsize ## Installing objsize Before you install: Low friction: pure Python wheel with no runtime dependencies and no compiled extensions. Package status is aging (208 days since last release), but the repository remains active and unarchived. License in practice: BSD-3-Clause is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions. Quickstart: pip install objsize==0.8.0 import objsize # Measure deep size of a dict including all nested objects size_bytes = objsize.get_deep_size(dict(arg1='hello', arg2='world')) print(size_bytes) # 340 # Measure multiple objects size_bytes = objsize.get_deep_size(['hello', 'world'], {'arg1': 'hello'}) print(size_bytes) # combined size Requires Python 3.8 or later. Verify before relying: - Whether the package handles all edge cases in modern Python versions beyond 3.8, or if there are known limitations with newer object types. - Performance characteristics when traversing very large object graphs or deeply nested structures. ## Package facts - License: BSD-3-Clause (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 3.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags python object memory size, deep size calculation, object memory usage bytes, python memory profiling, object graph traversal, nested object size, memory debugging python, memory-profiling, debugging, object-introspection [View on SkillFed](https://skillfed.io/packages/objsize) · [View on PyPI](https://pypi.org/project/objsize/)