Registry / web-framework / zope-configuration

zope-configuration

JSON →
library7.1pypypi✓ verified 84d ago

zope.configuration provides the Zope Configuration Markup Language (ZCML), a declarative XML-based configuration system used extensively in the Zope and Plone ecosystems. It allows applications to register components, utilities, and services, defining application behavior and structure through XML directives. The current stable version is 7.1, with releases typically tied to Zope/Plone ecosystem needs and Python compatibility.

pip install zope.configuration
INSTALL
IMPORT
SIG · ZOPE-CONFIGURATION
Z
zope-configuration
web-frameworkpythonv7.1
Install
2.1s avg
Import
154ms
Disk
20MB
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.920 runs
installs and imports cleanly · install 0.0s · import 0.164s · 21.5MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 2.1s · import 0.143s · 22MB
20MB installed
● package 20MB
Code
Verified usage

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

xmlconfig
from zope.configuration import xmlconfig
import zope.configuration.xmlconfig
While technically correct, direct import is less common; 'from ... import ...' is preferred for specific symbols.
ConfigurationContext
from zope.configuration.config import ConfigurationContext
ConfigurationError
from zope.configuration.exceptions import ConfigurationError

Demonstrates how to load a ZCML string, register a utility (a common use case), and retrieve it using `zope.component`. This example simulates a Python module to allow ZCML to reference classes by dotted name, which is crucial for ZCML's operation. Note: `zope.interface` and `zope.component` are fundamental for ZCML's utility and component registration features.

import sys from zope.interface import Interface, implementer from zope.configuration import xmlconfig from zope.component import getUtility, ComponentLookupError # --- Step 1: Define an interface and an implementation --- # These would typically reside in a real Python module. # For this self-contained quickstart, we simulate a module. class IMyService(Interface): """An interface for a dummy service.""" def do_something(): """Perform a dummy action.""" @implementer(IMyService) class MyService: """A simple implementation of IMyService.""" def do_something(self): return "Service action complete from ZCML!" # Simulate a module for ZCML to find the classes # In a real application, 'quickstart_module' would be a package with your classes. class DummyModule: IMyService = IMyService MyService = MyService sys.modules['quickstart_module'] = DummyModule # --- Step 2: Define a ZCML configuration string --- zcml_content = """ <configure xmlns="http://namespaces.zope.org/zope" i18n_domain="my.package"> <utility factory="quickstart_module.MyService" provides="quickstart_module.IMyService" name="my.unique.service" /> </configure> """ # --- Step 3: Load and process the ZCML configuration --- try: # xmlconfig.string processes the ZCML and registers components context = xmlconfig.string(zcml_content) # --- Step 4: Verify the utility was registered --- service = getUtility(IMyService, name="my.unique.service") print(f"Utility loaded successfully. Action: {service.do_something()}") except ComponentLookupError: print("Error: Utility not found after ZCML processing. Check ZCML registration.") except Exception as e: print(f"An error occurred during ZCML loading: {e}") finally: # Clean up the dummy module to avoid side effects in other tests/runs if 'quickstart_module' in sys.modules: del sys.modules['quickstart_module']
Debug
Known issues
breakingPython 3.10 or newer is now required. Older Python 3 versions (3.6-3.9) are no longer supported since version 7.0.
fix
Upgrade your Python environment to 3.10 or a newer compatible version.
affects: 7.0+
gotchaZCML directives like `factory` and `provides` reference Python objects (classes, interfaces) by dotted names (e.g., `my.package.MyClass`). These objects must be discoverable and importable by Python's module system when ZCML is processed. If ZCML cannot find the referenced module or class, it will raise an `ImportError` or `ConfigurationError`.
fix
Ensure the Python modules containing your classes/interfaces are correctly installed and on the `sys.path`, or for quickstarts/tests, temporarily add them to `sys.modules` as demonstrated in the quickstart.
affects: All versions
gotchaMissing or incorrect namespace declarations (`xmlns`, `xmlns:prefix`) in ZCML files can lead to directives not being recognized or parsing errors. Every ZCML file and every custom directive from another package needs its proper namespace declaration.
fix
Always include the default Zope namespace (`xmlns="http://namespaces.zope.org/zope"`) and any specific namespaces for directives used from other packages (e.g., `xmlns:browser="http://namespaces.zope.org/browser"`) in your `<configure>` tag or relevant directive tags.
affects: All versions
gotchaThe order of ZCML configuration matters. Later declarations can override earlier ones, particularly when registering utilities, adapters, or views with the same name/interface/for parameters. This can lead to unexpected behavior if not understood.
fix
Be mindful of the order in which ZCML files are loaded (e.g., through `include` directives or programmatic loading) and how directives are declared. If you intend to override, ensure the overriding declaration comes after the original.
affects: All versions
Errors
Common errors & fixes
ConfigurationError: No such directive 'my:directive'
The specified ZCML directive is not recognized, usually because its defining package's configuration was not included or the namespace prefix is incorrect.
fix
Ensure the ZCML file defining the directive is properly included (e.g., `<include package=".my_package" file="configure.zcml" />`) and the namespace prefix is correctly declared in the root `<configure>` element (e.g., `<configure xmlns:my="http://my.namespace.org/my_schema">`).
ConfigurationError: The 'utility' directive requires a 'provides' attribute.
A ZCML directive was used without a mandatory attribute, such as the `provides` attribute required for the `<utility>` directive.
fix
Add the missing attribute to the directive; for `<utility>`, specify the interface it implements (e.g., `<utility component=".path.to.MyUtility" provides=".interfaces.IMyUtility" />`).
ModuleNotFoundError: No module named 'zope.configuration'
The `zope.configuration` package has not been installed in the current Python environment.
fix
Install the package using pip: `pip install zope.configuration`
ConfigurationConflictError: Conflicting configuration actions
Two or more ZCML directives attempt to register the same component, utility, or adapter with identical identifiers, leading to a conflict.
fix
Review your ZCML files to identify and eliminate duplicate registrations or adjust your includes to prevent multiple definitions of the same item.
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line X, column Y
The ZCML file is not well-formed XML, containing basic syntax errors like unclosed tags, invalid characters, or incorrect nesting.
fix
Inspect the ZCML file at the specified line and column for any XML syntax errors, such as missing closing tags, incorrect attribute quotes, or invalid character entities.
Upgrade
Version history
7.1latest on PyPI · released Apr 10, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
45 hits · last 30 days
node
38
OpenAI (training)
1
Resources
zope-configuration — pip install zope-configuration · libregistry