skillfed

objsize

Traversal over Python's objects subtree and calculate the total size of the subtree in bytes (deep size).

objsize v0.8.0 3.0M downloads/30d#2,795 on PyPI44
Permissive license BSD-3-Clause AGING released

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 on this page — 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

objsize on PyPI

pip

pip install objsize

uv

uv add objsize

poetry

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 the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 208 days since the last release
Last repo commit
First released
Downloads 2,995,494/month — #2,795 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: objsize-0.8.0-py3-none-any.whl

Keywords: object-size, recursive, deep, traversal, object, size, debug, deep-object-size

License :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Software Development :: Libraries :: Python Modules

Tags

python object memory sizedeep size calculationobject memory usage bytespython memory profilingobject graph traversalnested object sizememory debugging python
memory-profilingdebuggingobject-introspection

More Python Modules packages