objsize
Traversal over Python's objects subtree and calculate the total size of the subtree in bytes (deep size).
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 objsizeuv
uv add objsizepoetry
poetry add objsizeInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
PymplerPympler measures, monitors, and analyzes memory…
permissive · top 5,000 on PyPI
tensordictTensorDict is a batched, nested dictionary…
permissive · top 5,000 on PyPI
recursive-diffRecursively compares two Python data structures…
permissive · top 15,000 on PyPI
deepdiffDeepDiff compares dictionaries, iterables,…
permissive · top 1,000 on PyPI
backports.weakrefBackports the `weakref.finalize` class from…
permissive · top 5,000 on PyPI
weakrefmethodProvides a WeakMethod class for storing bound…
permissive · top 15,000 on PyPI
tensordict-nightlyTensorDict is a batched, nested dictionary…
permissive · top 15,000 on PyPI
anytreeProvides a lightweight Python library for…
unclear · top 5,000 on PyPI
objectoryProvides dynamic object factory implementations…
permissive · top 15,000 on PyPI
lazy-object-proxyProvides a proxy object that defers execution…
permissive · top 1,000 on PyPI