Registry / web-framework / zope-component

zope-component

JSON →
library7.1pypypi✓ verified 21d ago

zope.component, along with zope.interface, provides a robust component architecture for Python, enabling the definition, registration, and lookup of loosely coupled components such as adapters and utilities. It is a core part of the Zope Toolkit project. The current version is 7.1. New minor versions are released roughly every 2-6 months, and major versions every 2-3 years, following semantic versioning.

pip install zope.component
INSTALL
IMPORT
SIG · ZOPE-COMPONENT
Z
zope-component
web-frameworkpythonv7.1
Install
2.2s avg
Import
43ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.1 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.046s · 20.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.040s · 21MB
19MB installed
● package 19MB
Code
Verified usage

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

getUtility
from zope.component import getUtility
provideUtility
from zope.component import provideUtility
queryUtility
from zope.component import queryUtility
IComponent
from zope.interface.interfaces import IComponent
from zope.component.interfaces import IComponent
Backwards compatibility imports for zope.component.interfaces were removed in version 5.0.0. These interfaces should now be imported directly from zope.interface.interfaces.
ComponentRegistry
from zope.interface.registry import ComponentRegistry
from zope.component.registry import ComponentRegistry
Backwards compatibility imports for zope.component.registry were removed in version 5.0.0. These classes should now be imported directly from zope.interface.registry.

This quickstart demonstrates the core functionality of zope.component: defining an interface, implementing it, and then registering and retrieving a utility. Utilities are singletons or named instances that provide a specific interface and can be looked up through the component registry.

from zope.interface import Interface, implementer from zope.component import provideUtility, getUtility, queryUtility, ComponentLookupError # 1. Define an Interface class IGreeter(Interface): """The Greeter interface provides a greeting method.""" def greet(name: str) -> str: """Say hello to the given name.""" # 2. Implement the Interface @implementer(IGreeter) class HelloGreeter: """A simple greeter component.""" def greet(self, name: str) -> str: return f"Hello, {name}!" # 3. Register the Utility # A utility is a component looked up by an interface and an optional name. # We can register an instance of the Greeter. my_greeter_instance = HelloGreeter() provideUtility(my_greeter_instance, IGreeter, name='default-greeter') # You can also register without a name for a singleton utility for the interface provideUtility(HelloGreeter(), IGreeter) # No name, becomes default for IGreeter # 4. Look up and use the Utility # Using getUtility (raises ComponentLookupError if not found) try: default_greeter = getUtility(IGreeter) print(f"Default greeting: {default_greeter.greet('World')}") except ComponentLookupError: print("Default greeter not found.") try: named_greeter = getUtility(IGreeter, name='default-greeter') print(f"Named greeting: {named_greeter.greet('Alice')}") except ComponentLookupError: print("Named greeter not found.") # Using queryUtility (returns None if not found, or a default value if specified) missing_greeter = queryUtility(IGreeter, name='non-existent') print(f"Querying missing greeter (should be None): {missing_greeter}") fallback_greeter = queryUtility(IGreeter, name='non-existent', default='Fallback') print(f"Querying with fallback: {fallback_greeter}")
Debug
Known issues
breakingBackwards compatibility imports from `zope.component.interfaces`, `zope.component.registry`, and the entire `zope.component.hookable` module were removed.
fix
Update imports to directly use `zope.interface.interfaces` or `zope.interface.registry`. Replace usage of `zope.component.hookable` with modern alternatives.
affects: 5.0.0 (2021-03-19) and later
breakingDropped support for older Python versions, requiring Python 3.7+ (for 6.1+), Python 3.10+ (for 7.1+).
fix
Ensure your project runs on a supported Python version (currently >=3.10 for zope.component 7.x).
affects: 6.0 (2023-04-14) and later (dropped 2.7, 3.5, 3.6). 6.1 (2025-09-09) and later (dropped 3.7, 3.8). 7.1 (2026-02-03) and later (dropped 3.9).
breakingReplaced `pkg_resources` namespace with PEP 420 native namespace.
fix
This is primarily an internal packaging change. If you rely on internal `pkg_resources` mechanisms related to `zope.component`'s namespace, you may need to update your code to reflect PEP 420 standards.
affects: 7.0 (2025-09-12) and later
gotchaThe declaration-order of interfaces being adapted to is important for adapter lookup. It must be the same as the order of parameters given to the adapter and used to query the adapter.
fix
Always ensure the order of interfaces specified in adapter declarations and subsequent lookups matches precisely.
affects: All versions
Errors
Common errors & fixes
zope.component.ComponentLookupError: ('No such adapter', <object at 0x...>, <InterfaceClass ...>) [for example: ('No such adapter', <MyObject object at 0x...>, <InterfaceClass mymodule.IMyAdapter>)]
An adapter was requested for a specific object type and an interface, but no matching adapter was registered in the component registry, or the registration parameters (for_, provides, name) did not align with the lookup request.
fix
Ensure the adapter class is correctly registered using `zope.component.provideAdapter(adapter_class, for_=IInputObject, provides=IAdaptedObject, name='optional_name')` and that the `getAdapter` call matches these parameters, including any optional name.
zope.component.ComponentLookupError: No such utility: <InterfaceClass ...> [for example: No such utility: <InterfaceClass mymodule.IMyUtility>]
A utility was requested for a specific interface, but no utility was registered in the component registry for that interface, or the registration parameters (provides, name) did not align with the lookup request.
fix
Register the utility instance or factory using `zope.component.provideUtility(utility_instance_or_factory, provides=IUtilityInterface, name='optional_name')` and ensure the `getUtility` call matches the interface and any specified name.
zope.interface.verify.MissingImplementation: The object <ClassName> does not implement the <InterfaceClass 'IInterface'> interface. [for example: The object <MyAdapter at 0x...> does not implement the <InterfaceClass 'my_package.interfaces.IMyInterface'> interface.]
An object (often an adapter or utility) is declared to implement a specific `zope.interface`, but it is missing one or more methods, attributes, or properties defined by that interface, or their signatures do not match.
fix
Modify the `ClassName` to include all methods, attributes, and properties specified in `IInterface`, ensuring their names and signatures (method arguments, return types) precisely match the interface definition.
Upgrade
Version history
7.1latest on PyPI · released Feb 3, 2026
Audit
Dependencies
zope.interfacerequiredProvides facilities for defining interfaces, which are fundamental to the Zope Component Architecture for describing components. It is a core dependency.
Agent activity
51 hits · last 30 days
node
42
OpenAI (training)
1
Resources
zope-component — pip install zope-component · libregistry