{"id":6303,"library":"zope-proxy","title":"Zope Proxy","description":"zope.proxy is a Python library providing generic, transparent proxies. It allows you to wrap an object with a proxy that delegates most operations to the underlying object, while still allowing for custom behavior or interception. The current version is 7.1, with releases typically tied to Python version support and bug fixes.","status":"active","version":"7.1","language":"en","source_language":"en","source_url":"https://github.com/zopefoundation/zope.proxy","tags":["proxy","zope","transparency","design-pattern"],"install":[{"cmd":"pip install zope-proxy","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Proxy","correct":"from zope.proxy import Proxy"},{"symbol":"getProxiedObject","correct":"from zope.proxy import getProxiedObject"},{"symbol":"isproxy","correct":"from zope.proxy import isproxy"}],"quickstart":{"code":"from zope.proxy import Proxy, getProxiedObject\n\nclass MyObject:\n    def __init__(self, value):\n        self.value = value\n\n    def get_value(self):\n        return self.value\n\n    def __repr__(self):\n        return f\"<MyObject value={self.value}>\"\n\n# Create an instance of MyObject\nobj = MyObject(42)\nprint(f\"Original object: {obj}\")\n\n# Wrap it with a Proxy\nproxied_obj = Proxy(obj)\nprint(f\"Proxied object: {proxied_obj}\")\n\n# Interact with the proxy - it behaves like the original object\nprint(f\"Value via proxy: {proxied_obj.value}\")\nprint(f\"Method call via proxy: {proxied_obj.get_value()}\")\n\n# Check if it's a proxy\nfrom zope.proxy import isproxy\nprint(f\"Is proxied_obj a proxy? {isproxy(proxied_obj)}\")\n\n# Get the original object back from the proxy\noriginal_from_proxy = getProxiedObject(proxied_obj)\nprint(f\"Original object retrieved from proxy: {original_from_proxy}\")\nassert original_from_proxy is obj\n\n# Demonstrate transparency for isinstance\nprint(f\"isinstance(proxied_obj, MyObject)? {isinstance(proxied_obj, MyObject)}\")","lang":"python","description":"This quickstart demonstrates how to create a transparent proxy for an object using `zope.proxy.Proxy`, interact with it, and retrieve the original object using `zope.proxy.getProxiedObject`. It also shows how `isinstance` works transparently."},"warnings":[{"fix":"Ensure your project's Python environment is 3.10 or newer. For older Python versions, you may need to pin to an earlier zope.proxy version (e.g., 6.x for Python 3.7-3.9, 5.x for Python 3.6).","message":"Major versions (5.x, 6.x, 7.x) of zope.proxy have progressively dropped support for older Python versions. Version 7.x (including 7.1) requires Python 3.10 or newer. Attempting to install or use it on older Python versions will fail.","severity":"breaking","affected_versions":"5.0.0, 6.0.0, 7.0.0 onwards"},{"fix":"Manually implement `zope.interface` concerns on your proxied objects or manage interface registration directly. Review code that assumed `zope.proxy` handled `zope.interface` aspects implicitly.","message":"Starting with version 5.0.0, the `zope.interface` dependency and its integration (like `zope.proxy.non_proxied` and automatic interface implementation) were removed. If your application relied on proxies automatically adapting to or implementing `zope.interface` definitions, this will break.","severity":"breaking","affected_versions":"5.0.0 onwards"},{"fix":"Prefer `isinstance(proxied_object, OriginalClass)` for type checks, as `zope.proxy` typically handles this transparently. If you need the exact type of the original object, retrieve it first using `getProxiedObject(proxied_object)` and then call `type()` on the result.","message":"While `zope.proxy` aims for transparency, `type(proxied_object)` will return `<class 'zope.proxy.Proxy'>`, not the type of the underlying proxied object. Code that strictly checks `type()` for identity will not see the original object's type.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}