{"id":9423,"library":"zope-container","title":"Zope Container","description":"Zope Container (`zope.container`) is a foundational Python library within the Zope ecosystem, defining interfaces for object container components and providing concrete implementations like BTreeContainer and OrderedContainer. It serves as a building block for dynamic web applications and content management systems such as Plone, offering mechanisms for object persistence, integrity, and access control. Currently at version 7.2, the library maintains an active release cadence, frequently updating to support new Python versions and integrating changes from other Zope core packages.","status":"active","version":"7.2","language":"en","source_language":"en","source_url":"https://github.com/zopefoundation/zope.container","tags":["zope","container","data structures","interfaces","btree","persistence"],"install":[{"cmd":"pip install zope-container","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"BTreeContainer","correct":"from zope.container.btree import BTreeContainer"},{"symbol":"OrderedContainer","correct":"from zope.container.ordered import OrderedContainer"},{"symbol":"IContainer","correct":"from zope.container.interfaces import IContainer"},{"symbol":"IWriteContainer","correct":"from zope.container.interfaces import IWriteContainer"}],"quickstart":{"code":"from zope.container.btree import BTreeContainer\nfrom zope.interface import implementer\nfrom zope.container.interfaces import IContainer\n\n@implementer(IContainer)\nclass MyContainer(BTreeContainer):\n    \"\"\"A simple container demonstrating zope.container.\"\"\"\n    pass\n\n\ncontainer = MyContainer()\ncontainer['item1'] = 'First Value'\ncontainer['item2'] = 123\n\nprint(f\"Container has {len(container)} items.\")\nprint(f\"Item 1: {container['item1']}\")\n\n# Iterating through a container\nfor key, value in container.items():\n    print(f\"Key: {key}, Value: {value}\")\n","lang":"python","description":"This quickstart demonstrates creating a basic BTreeContainer, implementing IContainer (a common pattern in Zope to declare interface adherence), and then adding and retrieving items. This showcases the core container functionality."},"warnings":[{"fix":"Upgrade your Python interpreter to a supported version or pin `zope-container` to an older version compatible with your Python environment. Refer to PyPI for specific version requirements.","message":"Major versions of `zope.container` (e.g., 5.0, 6.0, 7.0, 7.1) frequently drop support for older Python versions. Ensure your environment meets the `requires_python` specification (currently >=3.10 for 7.2).","severity":"breaking","affected_versions":"5.0, 6.0, 7.0, 7.1, 7.2"},{"fix":"Ensure your project's packaging and import mechanisms are compatible with PEP 420 namespace packages. This is typically handled automatically by modern Python packaging tools, but older setups might require adjustment.","message":"Version 7.0 of `zope.container` (and other Zope packages) migrated from `pkg_resources` to PEP 420 native namespace packages. This can affect how sub-packages are discovered and imported in complex Zope deployments.","severity":"breaking","affected_versions":">=7.0"},{"fix":"Update code that declares interfaces or implementations to use the `@implementer` and `@provider` decorators from `zope.interface`. For example, replace `implements(IMyInterface)` with `@implementer(IMyInterface)`.","message":"Older versions of `zope.interface` (a core dependency) had significant breaking changes in version 6.0 and 7.0, including the removal of deprecated `implements` and `classProvides` functions in favor of `@implementer` and `@provider` decorators. Although `zope.container` itself adopted these earlier (e.g., 4.0.0a1 for `implementer`), downstream code might break.","severity":"breaking","affected_versions":"Zope.interface versions >=6.0.0, indirectly affecting zope.container users with old interface declarations."},{"fix":"If working with very old code or migrating from it, update exception handling to catch `KeyError` and `ValueError` instead of the former `zope.exceptions` types.","message":"Before `zope.container` version 3.7.1, certain container operations raised custom exceptions like `zope.exceptions.DuplicationError` or `zope.exceptions.UserError`. These were changed to standard Python exceptions `KeyError` and `ValueError` respectively.","severity":"gotcha","affected_versions":"<3.7.1"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Consult the `zope.container` changelog or the documentation for the specific Zope package that the module belongs to. For example, `IContained` moved to `zope.location.interfaces` in older versions.","cause":"An import path for a Zope component has changed, or a compatibility import has been removed in a newer version of `zope.container` or a related Zope package.","error":"ImportError: No module named 'zope.container.old_module'"},{"fix":"Verify that all classes intended to implement `zope.container` interfaces (like `IContainer`, `IWriteContainer`) correctly use the `@implementer` decorator from `zope.interface` and that the object itself is registered or configured to be adaptable. Ensure `zope.interface` and other Zope packages are compatible versions.","cause":"This often indicates a mismatch in interface declarations or an object not properly implementing a required interface, especially after updates to `zope.interface` or related Zope packages.","error":"TypeError: ('Could not adapt', <object>, <Interface>)"},{"fix":"Ensure that keys used for adding or accessing items in a container are unique and adhere to naming conventions (e.g., non-empty, valid string characters). Handle `KeyError` for non-existent items or `ValueError` for invalid names.","cause":"In modern versions (>=3.7.1), `zope.container` raises standard `KeyError` for duplication or missing keys and `ValueError` for invalid input (e.g., empty or disallowed characters in names) during item addition/retrieval.","error":"KeyError: 'item_name' or ValueError: 'Invalid item name'"}]}