Registry / web-framework / zope-site

zope-site

JSON →
library6.0pypypiunverified

zope.site is a foundational Python library that provides local registries for the Zope Component Architecture (ZCA). It enables the creation and retrieval of localized component managers (site managers) for specific object contexts, allowing components to be registered and looked up dynamically based on their position in an object hierarchy. The current version is 6.0, and its release cadence is tied to the broader Zope ecosystem.

pip install zope.site
INSTALL
IMPORT
SIG · ZOPE-SITE
Z
zope-site
web-frameworkpythonv6.0
Install
5.2s avg
Import
Disk
48MB
Pass rate
5/ 10
Env Coverage5 / 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.910 runs
build_error
glibc
py 3.103.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')}")
Debug
Known issues
breaking`zope.site` dropped support for Python 3.7 and 3.8 in version 6.0.
fix
Ensure your project runs on Python 3.9 or newer. Upgrade your Python environment if necessary.
affects: 6.0+
gotchaRegistrations made within a `provideSite` context manager block are local to that site and do not persist globally or outside that specific context.
fix
Always remember that `provideSite` creates a temporary, localized scope for ZCA registrations. If a component needs to be accessible globally, register it before entering any local site context.
affects: All versions
gotchaWhen looking up components using `zope.component.getUtility` (or similar) within a local site, the lookup order is local registry first, then the global registry. This can lead to unexpected behavior if a component is registered globally and then also locally with the same name/interface.
fix
Be mindful of component naming and interface usage across global and local scopes. Ensure that local components either provide unique interfaces/names or are intended to override global ones within their specific context.
affects: All versions
gotchaThe `provideSite` function (and other core site-related utilities) is located in the `zope.site.site` submodule, not directly in `zope.site`.
fix
Use `from zope.site.site import provideSite` instead of `from zope.site import provideSite` to avoid `ImportError`.
affects: All versions
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.
Agent activity
47 hits · last 30 days
node
42
OpenAI (training)
1
Resources
zope-site — pip install zope-site · libregistry