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.239s · 33.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.9s · import 0.226s · 35MB
37MB installed
● package 37MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
traverse
✓ from zope.traversing.api import traverse
ITraversable
✓ from zope.traversing.interfaces import ITraversable
IPathAdapter
✓ from zope.traversing.interfaces import IPathAdapter
absoluteURL
✓ from zope.traversing.browser import absoluteURL
✗ from zope.traversing.browser import AbsoluteURL
The class AbsoluteURL was deprecated and removed in favor of the function absoluteURL in v4.0.
This quickstart demonstrates how to define a simple object hierarchy using `ITraversable` and then navigate it using `zope.traversing.api.traverse`. It sets up a root folder containing sub-folders and documents, and shows how to retrieve an item by its path, as well as how `KeyError` (or `zope.traversing.interfaces.NotFound` in more complex setups) is raised for non-existent paths.
from zope.interface import implementer
from zope.traversing.interfaces import ITraversable
from zope.traversing.api import traverse
# Define a simple traversable object (e.g., a Folder)
@implementer(ITraversable)
class Folder:
def __init__(self, name, parent=None):
self.__name__ = name
self.__parent__ = parent
self.contents = {}
def __setitem__(self, name, item):
item.__name__ = name
item.__parent__ = self
self.contents[name] = item
def __getitem__(self, name):
if name in self.contents:
return self.contents[name]
raise KeyError(f"No item named '{name}'")
def traverse(self, name, furtherPath): # furtherPath is usually ignored for simple dict-like traversal
# Default traversal: look up in contents
return self.contents[name]
def __repr__(self):
return f"<Folder '{self.__name__}'>"
class Document:
def __init__(self, name, content="", parent=None):
self.__name__ = name
self.__parent__ = parent
self.content = content
def __repr__(self):
return f"<Document '{self.__name__}'>"
# Build a hierarchy
root = Folder('')
products_folder = Folder('products')
root['products'] = products_folder
products_folder['book1'] = Document('book1', "The first book.")
products_folder['book2'] = Document('book2', "The second book.")
# Traverse to an item
try:
item = traverse(root, 'products/book1')
print(f"Found item at 'products/book1': {item}")
# Attempt to traverse to a non-existent item
non_existent_item = traverse(root, 'products/nonexistent')
print(f"Found non-existent item: {non_existent_item}") # This line won't be reached
except KeyError as e:
print(f"Error traversing to 'products/nonexistent': {e} (expected behavior)")
# Traverse to a sub-path within an item if it also implements ITraversable
# (not shown in this basic example for Document, but would work for nested Folders)
Errors
Common errors & fixes
ImportError: cannot import name 'AbsoluteURL' from 'zope.traversing.browser'
Attempting to import the `AbsoluteURL` class, which was deprecated and removed in `zope.traversing` version 4.0.
fixInstead of `from zope.traversing.browser import AbsoluteURL`, use the utility function: `from zope.traversing.browser import absoluteURL`.
TypeError: traverse() missing 1 required positional argument: 'path'
The `zope.traversing.api.traverse` function requires at least two arguments: the object to start traversing from and the path string.
fixEnsure you call `traverse` with both the root object and the path, e.g., `traverse(root_object, 'segment1/segment2')`.
KeyError: 'some_missing_name'
The traversal mechanism (`ITraversable`'s `traverse` method or `IPathAdapter`) could not find an object matching the current path segment.
fixThis is often expected behavior. If it's not, verify the path string is correct, ensure the intermediate objects in the hierarchy are correctly set up and implement `ITraversable` (or have registered `IPathAdapter`s), and that the names exist within their respective containers.
Upgrade
Version history
6.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredCore Zope component for defining interfaces, central to Zope's object model and traversal contracts.
zope.locationrequiredProvides __name__ and __parent__ attributes, which are fundamental for defining an object hierarchy that traversal operates on.
zope.schemarequiredUsed for schema definitions, potentially for defining traversal-related configuration or data structures.