zope.index
raw JSON → 8.1 verified Fri May 01 auth: no python maintenance
Provides index implementations (field, text, set, etc.) for use with cataloging systems. Version 8.1, requires Python 3.10+. Maintenance mode.
pip install zope.index Common errors
error AttributeError: module 'zope.index' has no attribute 'FieldIndex' ↓
cause Importing from top-level instead of submodule.
fix
Use 'from zope.index.field import FieldIndex'
error zope.interface.interface.InvalidInterface: '...' is not a valid interface ↓
cause Incorrect interface passed to index constructor (e.g., fieldname wrong).
fix
Check that the interface attribute exists and matches the name expected by the index.
Warnings
deprecated zope.index is in maintenance mode. No new features likely. Consider alternatives if starting fresh. ↓
fix Evaluate if you need full Zope catalog stack; many use cases can be replaced with plain dicts.
gotcha After indexing, you must explicitly apply pending updates via index.updateIndex() for some index types (e.g., SetIndex) before search works. ↓
fix Call index.updateIndex() after batch indexing operations to flush changes.
Imports
- FieldIndex wrong
from zope.index import FieldIndexcorrectfrom zope.index.field import FieldIndex - TextIndex wrong
from zope.index import TextIndexcorrectfrom zope.index.text import TextIndex - SetIndex wrong
from zope.index import SetIndexcorrectfrom zope.index.set import SetIndex
Quickstart
from zope.index.field import FieldIndex
index = FieldIndex()
index.index_object(1, 'value1')
index.index_object(2, 'value2')
hits = index.search({'any_of': ('value1',)})
print(hits)
# Result: {1: 1}