Install & Compatibility
Where this runs
tested against v6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.031s · 19.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.2s · import 0.027s · 21MB
22MB installed
● package 22MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
ISized
✓ from zope.size.interfaces import ISized
get_size
✓ from zope.size import get_size
This quickstart demonstrates how to define an object, create an adapter that implements `zope.size.interfaces.ISized` for that object's interface, register the adapter using `zope.component.provideAdapter`, and then retrieve the object's size using the `zope.size.get_size` utility function. It highlights the crucial step of adapter registration.
import zope.interface
import zope.component
from zope.size.interfaces import ISized
from zope.size import get_size
# 1. Define an interface for our object
class IMyObject(zope.interface.Interface):
"""An object with some data."""
# 2. Define a class implementing the interface
@zope.interface.implementer(IMyObject)
class MyObject:
def __init__(self, items):
self.items = items
# 3. Define an adapter that provides ISized for IMyObject
@zope.component.adapter(IMyObject)
@zope.interface.implementer(ISized)
class MyObjectSizer:
def __init__(self, context):
self.context = context
@property
def size(self):
return len(self.context.items)
# 4. Create an instance of our object
my_list_obj = MyObject([1, 2, 3, 4, 5])
my_dict_obj = MyObject({'a': 1, 'b': 2})
# 5. Register the adapter (typically done at application startup)
zope.component.provideAdapter(MyObjectSizer)
# 6. Use get_size to retrieve the size
list_size = get_size(my_list_obj)
dict_size = get_size(my_dict_obj)
# Print the results
print(f"Size of list object: {list_size}")
print(f"Size of dictionary object: {dict_size}")
# Example of an object without a registered adapter
class UnsizedObject: pass
unsized_obj = UnsizedObject()
try:
get_size(unsized_obj)
except zope.component.interfaces.ComponentLookupError as e:
print(f"\nError for unsized object (expected): {e}")
Errors
Common errors & fixes
zope.component.interfaces.ComponentLookupError: No registered adapter for (...) for zope.size.interfaces.ISized
The `get_size` function could not find an adapter that implements `ISized` for the type of object you passed.
fixYou must register an adapter using `zope.component.provideAdapter(YourSizerClass)` before calling `get_size` for objects of that type. Ensure your adapter correctly implements `ISized` and is registered for the correct interface/type.
AttributeError: 'YourSizerClass' object has no attribute 'size'
Your adapter class implementing `ISized` defines `size` as a regular method or is missing it entirely, instead of a property.
fixEnsure the `size` attribute in your adapter is defined as a property using the `@property` decorator:
```python
@zope.interface.implementer(ISized)
class YourSizer:
def __init__(self, context):
self.context = context
@property
def size(self):
return len(self.context.data)
``` TypeError: object of type 'YourObject' has no len()
You are likely attempting to use `len()` directly on an object for which `zope.size` is intended, but `len()` is not defined for that object. You should be using `get_size()` with an appropriate adapter.
fixInstead of `len(my_object)`, ensure you have an `ISized` adapter registered for `my_object`'s type/interface, and then use `get_size(my_object)`.
Upgrade
Version history
6.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredCore dependency for defining and implementing interfaces used by zope.size.
zope.componentrequiredRequired for registering and looking up adapters that provide size information.