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.148s · 22.1MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 2.6s · import 0.137s · 23MB
24MB installed
● package 24MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
IAnnotations
✓ from zope.annotation.interfaces import IAnnotations
✗ from zope.annotation import IAnnotations
Interfaces are typically found in the `.interfaces` submodule within Zope packages.
IAnnotatable
✓ from zope.annotation.interfaces import IAnnotatable
Required to mark an object as capable of being annotated.
This example demonstrates how to make an arbitrary object annotatable using `directlyProvides(obj, IAnnotatable)` and then use the `IAnnotations` adapter to store and retrieve key-value data on it. This pattern is fundamental for extending objects without inheritance in Zope-based applications.
from zope.interface import directlyProvides
from zope.annotation.interfaces import IAnnotations, IAnnotatable
# Define a simple class that can be annotated
class MyObject:
pass
# Instantiate the object
obj = MyObject()
# An object must provide IAnnotatable to be annotated.
# In a real Zope application, this might be handled by decorators or base classes.
# For a standalone example, we directly provide the interface.
directlyProvides(obj, IAnnotatable)
# Get the annotations adapter for the object
# If no annotations exist, a new empty dictionary-like object is created.
annotations = IAnnotations(obj)
# Store and retrieve data on the object via annotations
annotations['my_data_key'] = 'This is some data stored as an annotation.'
annotations['another_key'] = {'list': [1, 2, 3], 'dict_val': 'value'}
print(f"Annotation 'my_data_key': {annotations['my_data_key']}")
print(f"Annotation 'another_key': {annotations['another_key']}")
# Check if an annotation exists
if 'my_data_key' in annotations:
print("'my_data_key' exists in annotations.")
# Delete an annotation
del annotations['my_data_key']
if 'my_data_key' not in annotations:
print("'my_data_key' successfully deleted.")
Errors
Common errors & fixes
TypeError: Could not adapt <__main__.MyObject object at 0x...> to <InterfaceClass zope.annotation.interfaces.IAnnotations>
The object you are trying to annotate does not provide the `IAnnotatable` interface, which is a prerequisite for `zope.annotation` to function.
fixBefore attempting to get `IAnnotations(obj)`, ensure `obj` provides `IAnnotatable`. For testing or simple cases, use `from zope.interface import directlyProvides; directlyProvides(obj, IAnnotatable)`.
ImportError: cannot import name 'IAnnotations' from 'zope.annotation'
The `IAnnotations` interface is not directly under the `zope.annotation` package but within its `interfaces` submodule.
fixChange your import statement to `from zope.annotation.interfaces import IAnnotations`.
AttributeError: 'dict' object has no attribute '_p_jar'
You are attempting to store a non-persistent Python dictionary (or other non-persistent object) as an annotation on a persistent object within a ZODB, and ZODB is trying to make the *value* persistent but it doesn't know how.
fixIf you need a persistent dictionary for annotations, use a persistent collection type from `ZODB.blob` or `BTrees`. For example, `from persistent.mapping import PersistentMapping; annotations['my_persistent_dict'] = PersistentMapping({'key': 'value'})`. Upgrade
Version history
6.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredProvides the core interface (`IAnnotations`, `IAnnotatable`) definitions and implementation features required by `zope.annotation`.