Registry / web-framework / zope-location

zope-location

JSON →
library6.0pypypi✓ verified 84d ago

Zope Location is a small, focused library from the Zope Foundation providing an interface and a default implementation for objects that know their hierarchical position via `__parent__` and `__name__` attributes. It's a foundational component for traversal in many Zope-based applications. The current version is 6.0. It follows the Zope Foundation's release cadence, typically releasing new major versions to drop old Python support or introduce minor enhancements.

pip install zope.location
INSTALL
IMPORT
SIG · ZOPE-LOCATION
Z
zope-location
web-frameworkpythonv6.0
Install
2.4s avg
Import
116ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.120s · 21.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.4s · import 0.112s · 22MB
23MB installed
● package 23MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Location
from zope.location.location import Location
The primary implementation class for located objects, providing `__parent__` and `__name__` attributes.
ILocation
from zope.location.interfaces import ILocation
The interface defining the contract for objects that can be located within a hierarchy (i.e., having `__parent__` and `__name__`).
Located
from zope.location.location import Located
A mixin class that provides the basic `__parent__` and `__name__` attributes, suitable for multiple inheritance with other base classes.

This example demonstrates how to create a simple hierarchy of objects using `zope.location.location.Location`. It highlights the necessity of explicitly setting the `__parent__` and `__name__` attributes, which are central to `zope.location`, and verifies that the `ILocation` interface is correctly provided by the objects.

from zope.location.location import Location from zope.location.interfaces import ILocation # Define a simple located object by subclassing Location class MyLocatedObject(Location): def __init__(self, name=None, parent=None, value=None): # Explicitly set __name__ and __parent__ during initialization self.__name__ = name self.__parent__ = parent self.value = value # Create a hierarchy of located objects root = MyLocatedObject(name='', parent=None, value="I am the root") folder = MyLocatedObject(name='folder', parent=root, value="I am a folder object") item = MyLocatedObject(name='item', parent=folder, value="I am an item inside the folder") # Verify that the ILocation interface is provided by these objects assert ILocation.providedBy(root) assert ILocation.providedBy(folder) assert ILocation.providedBy(item) print(f"Root: {root.value} (name='{root.__name__}', parent={root.__parent__})") print(f"Folder: {folder.value} (name='{folder.__name__}', parent={folder.__parent__.value})") print(f"Item: {item.value} (name='{item.__name__}', parent={item.__parent__.value})") # Demonstrate traversal by accessing parent attributes print(f"\nAccessing parent from item: {item.__parent__.value}") print(f"Accessing parent's parent from item: {item.__parent__.__parent__.value}")
Debug
Known issues
gotchaThe `__parent__` and `__name__` attributes of `Location` objects are not automatically populated or managed upon instantiation. They are merely attributes that `zope.location` expects to exist.
fix
Always ensure you explicitly set `obj.__parent__ = parent_obj` and `obj.__name__ = 'obj_name'` after creating a `Location` instance, or handle their initialization within your custom class's `__init__` method.
affects: All versions
gotcha`zope.location.location.Location` objects are designed for 'locating' themselves within a hierarchy but do not inherently provide container functionality (e.g., dictionary-like `__getitem__` or `__setitem__`).
fix
If you need a located object to also act as a container for other located objects (e.g., a folder), you must implement the container methods (like `__getitem__`, `__setitem__`, `__delitem__`) yourself, typically in a subclass or by combining `Location` with another base class.
affects: All versions
breakingVersion 6.0 of `zope.location` dropped support for Python 3.8. It now explicitly requires Python 3.9 or newer to run.
fix
Before upgrading to or installing `zope.location==6.0`, ensure your project's Python environment is running Python 3.9 or a newer compatible version.
affects: 6.0 and later
Errors
Common errors & fixes
AttributeError: '__parent__'
You are attempting to access `obj.__parent__` or `obj.__name__` on a `zope.location.location.Location` instance, but these attributes have not yet been set or initialized.
fix
Ensure that you explicitly set `obj.__parent__ = parent_obj` and `obj.__name__ = 'child_name'` after creating your located object, or within its `__init__` method.
TypeError: 'Location' object is not subscriptable
You are trying to retrieve a child object from a `zope.location.location.Location` instance using dictionary-like indexing (e.g., `parent_obj['child_name']`). `Location` objects do not implement containment methods by default.
fix
If you require your located objects to also function as containers, you must implement the `__getitem__` (and potentially `__setitem__`, `__delitem__`) methods in your custom located class. `zope.location` itself focuses only on the location aspects.
Upgrade
Version history
6.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.interfacerequiredProvides the ILocation interface and adapter machinery used throughout the Zope ecosystem, which zope.location builds upon.
Agent activity
36 hits · last 30 days
node
30
OpenAI (training)
1
Resources
zope-location — pip install zope-location · libregistry