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
build_error
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 5.2s · import 0.000s · 43MB
48MB installed
● package 48MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
provideSite
✓ from zope.site import provideSite
✗ from zope.site import provideSite
This quickstart demonstrates how to use `zope.site.site.provideSite` to establish local component registries for different contexts. It shows how local registrations are isolated to their respective sites, while global registrations remain accessible from within local sites. Note the use of `zope.location.Located` for context objects, which is common in Zope applications.
import zope.component
import zope.interface
import zope.site.site
from zope.location import Located
# 1. Define an interface for your context and services
class IMyContext(zope.interface.Interface):
"""An interface for objects that can serve as local site contexts."""
class IMyService(zope.interface.Interface):
"""An interface for a service."""
# 2. Implement the context and service
@zope.interface.implementer(IMyContext)
class MyContext(Located): # Inherit from Located for Zope site integration
"""A sample context object that can host a local site."""
def __init__(self, name="Default"):
self.name = name
@zope.interface.implementer(IMyService)
class MyService:
"""A sample service implementation."""
def __init__(self, name):
self.name = name
def __repr__(self):
return f"<MyService: {self.name}>"
# 3. Register a global service
print("--- Global Scope ---")
zope.component.provideUtility(IMyService, MyService("Global Service"), name="shared_service")
print(f"Globally available: {zope.component.getUtility(IMyService, name='shared_service')}")
# 4. Create a context instance and establish a local site
context_a = MyContext("Context A")
print(f"\n--- Inside Local Site for {context_a.name} ---")
with zope.site.site.provideSite(context_a):
# Register a service locally for Context A
zope.component.provideUtility(IMyService, MyService("Local Service A"), name="my_local_service")
print(f"Local to {context_a.name}: {zope.component.getUtility(IMyService, name='my_local_service')}")
# Global service is still accessible
print(f"Global from {context_a.name}: {zope.component.getUtility(IMyService, name='shared_service')}")
# 5. Create another context and establish a different local site
context_b = MyContext("Context B")
print(f"\n--- Inside Local Site for {context_b.name} ---")
with zope.site.site.provideSite(context_b):
# Register a service locally for Context B (different from Context A's local service)
zope.component.provideUtility(IMyService, MyService("Local Service B"), name="my_local_service")
print(f"Local to {context_b.name}: {zope.component.getUtility(IMyService, name='my_local_service')}")
# Global service is still accessible
print(f"Global from {context_b.name}: {zope.component.getUtility(IMyService, name='shared_service')}")
# 6. Outside any local site
print("\n--- Outside any Local Site ---")
try:
# Attempting to access a local service will fail
zope.component.getUtility(IMyService, name="my_local_service")
except zope.component.ComponentLookupError as e:
print(f"Error: {e} (local service not available globally)")
print(f"Globally available: {zope.component.getUtility(IMyService, name='shared_service')}")
Upgrade
Version history
6.0latest on PyPI · released Sep 12, 2025
Audit
Dependencies
zope.componentrequiredProvides the core component architecture for registration and lookup.
zope.interfacerequiredRequired for defining interfaces and implementing them for ZCA objects.
zope.locationrequiredProvides the Located base class, useful for context objects that host local sites.