{"id":23026,"library":"zope.viewlet","title":"zope-viewlet","description":"Zope Viewlets provide a mechanism for reusable components in Zope-based web applications, enabling modular view rendering. Current version: 6.0, supported Python >=3.9. Release cadence is infrequent, tied to Zope framework updates.","status":"active","version":"6.0","language":"python","source_language":"en","source_url":"https://github.com/zopefoundation/zope.viewlet","tags":["zope","viewlet","web","component","zope3"],"install":[{"cmd":"pip install zope.viewlet","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Core dependency for interface definitions","package":"zope.interface","optional":false},{"reason":"Required for component architecture","package":"zope.component","optional":false},{"reason":"Provides page rendering support","package":"zope.browserpage","optional":false},{"reason":"Required for request/response handling","package":"zope.publisher","optional":false}],"imports":[{"note":"Direct import from __init__ fails; use the viewlet submodule.","wrong":"from zope.viewlet import ViewletBase","symbol":"ViewletBase","correct":"from zope.viewlet.viewlet import ViewletBase"},{"note":"Interfaces are in the interfaces submodule.","wrong":"from zope.viewlet import IViewletManager","symbol":"IViewletManager","correct":"from zope.viewlet.interfaces import IViewletManager"},{"note":"Manager class is in the manager submodule.","wrong":"from zope.viewlet import ViewletManagerBase","symbol":"ViewletManagerBase","correct":"from zope.viewlet.manager import ViewletManagerBase"}],"quickstart":{"code":"from zope.viewlet.viewlet import ViewletBase\nfrom zope.viewlet.manager import ViewletManagerBase\nfrom zope.viewlet.interfaces import IViewlet, IViewletManager\n\nclass MyViewlet(ViewletBase):\n    def update(self):\n        self.message = 'Hello from viewlet'\n    def render(self):\n        return f'<div>{self.message}</div>'\n\nclass MyManager(ViewletManagerBase):\n    pass\n\n# typical usage involves registration via ZCML or component architecture\nprint('Viewlet and Manager defined')","lang":"python","description":"Define a viewlet and manager. Viewlets must implement IViewlet, managers IViewletManager."},"warnings":[{"fix":"Ensure Python >=3.9. Update imports and remove any Python 2 compatibility code.","message":"6.0 drops support for Python 2 and Python <3.9. If upgrading from 5.x, check Python version compatibility.","severity":"breaking","affected_versions":"<6.0"},{"fix":"Override update() to set self.manager = manager or receive manager as argument.","message":"ViewletManagerBase no longer automatically assigns 'manager' attribute to viewlets. You must now pass it explicitly via update().","severity":"deprecated","affected_versions":">=6.0"},{"fix":"Use the appropriate submodule path: from zope.viewlet.viewlet import ViewletBase, from zope.viewlet.manager import ViewletManagerBase, from zope.viewlet.interfaces import IViewlet, etc.","message":"Importing directly from zope.viewlet (e.g., 'from zope.viewlet import ViewletBase') fails with AttributeError because submodules are not imported by default.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use: from zope.viewlet.viewlet import ViewletBase","cause":"Importing from the package root instead of the viewlet submodule.","error":"AttributeError: module 'zope.viewlet' has no attribute 'ViewletBase'"},{"fix":"Implement __getstate__ and __setstate__ in your manager class, or avoid pickling them.","cause":"Viewlet managers are not pickle-safe by default; common when using session or caching.","error":"TypeError: can't pickle ViewletManagerBase objects"},{"fix":"Install: pip install zope.viewlet. Verify with pip list.","cause":"Package not installed or Python environment not activated.","error":"ModuleNotFoundError: No module named 'zope.viewlet'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}