{"id":5559,"library":"zope-schema","title":"Zope Schema","description":"zope.schema is a Python library that extends zope.interface to provide detailed descriptions of object attributes, known as schemas. It enables defining data models, including field types, constraints, and validation methods, independent of specific storage or form libraries. The current version is 8.1, and it's actively maintained by the Zope Foundation with a release cadence tied to features and breaking changes, typically alongside the broader Zope ecosystem.","status":"active","version":"8.1","language":"en","source_language":"en","source_url":"https://github.com/zopefoundation/zope.schema","tags":["zope","schema","interface","validation","data-modeling"],"install":[{"cmd":"pip install zope.schema","lang":"bash","label":"Latest stable version"}],"dependencies":[{"reason":"zope.schema builds upon zope.interface to define schemas as extended interfaces.","package":"zope.interface","optional":false}],"imports":[{"symbol":"Interface","correct":"from zope.interface import Interface"},{"symbol":"TextLine","correct":"from zope.schema import TextLine"},{"symbol":"URI","correct":"from zope.schema import URI"},{"symbol":"Bool","correct":"from zope.schema import Bool"},{"symbol":"Choice","correct":"from zope.schema import Choice"}],"quickstart":{"code":"import zope.interface\nimport zope.schema\n\nclass IBookmark(zope.interface.Interface):\n    title = zope.schema.TextLine(\n        title='Title',\n        description='The title of the bookmark',\n        required=True\n    )\n    url = zope.schema.URI(\n        title='Bookmark URL',\n        description='URL of the Bookmark',\n        required=True\n    )\n\n@zope.interface.implementer(IBookmark)\nclass Bookmark(object):\n    title = None\n    url = None\n\nbm = Bookmark()\n\n# Example of validation (a common use case)\ntry:\n    IBookmark['title'].validate('My Awesome Bookmark')\n    IBookmark['url'].validate('http://example.com/bookmark')\n    print(\"Validation successful!\")\nexcept zope.schema.ValidationError as e:\n    print(f\"Validation failed: {e}\")","lang":"python","description":"This quickstart demonstrates how to define a schema using `zope.interface.Interface` and various `zope.schema` field types, then how to implement that schema in a Python class and perform basic validation."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or later. Refer to the zope.schema PyPI page or documentation for specific version compatibility.","message":"Python 2.7, 3.5, 3.6, 3.7, and 3.8 are no longer supported. Version 7.1 dropped support for Python 3.7 and 3.8, while Version 7.0 dropped support for Python 2.7, 3.5, and 3.6. Ensure your environment uses Python 3.9 or newer.","severity":"breaking","affected_versions":"7.0.0, 7.1.0"},{"fix":"Update your project's packaging configuration to use PEP 420 native namespaces if you encounter import issues after upgrading to 8.0 or higher.","message":"The `pkg_resources` namespace was replaced with PEP 420 native namespace in version 8.0. This might affect projects that relied on the older namespace packaging mechanism, especially in complex deployment scenarios.","severity":"breaking","affected_versions":"8.0.0"},{"fix":"For versions 6.1.0/6.1.1, explicitly set `required=True` on `Bool` fields if that is the desired behavior. Upgrade to a later version (e.g., 6.2.0 or higher) where this fix is in place.","message":"In versions 6.1.0 and 6.1.1, the `IBool.required` attribute's default behavior changed and was then fixed. Initially, `Bool` fields implicitly set `required` to `False`. If you explicitly relied on `required=True` for `Bool` fields in these versions, ensure your validation logic accounts for this, or upgrade to a newer version where the fix is applied.","severity":"gotcha","affected_versions":"6.1.0, 6.1.1"},{"fix":"Prefer using `source` arguments with `zope.schema.Choice` fields instead of `vocabulary`. Consult `zope.schema` documentation for examples of creating and using sources.","message":"The use of `vocabularies` with `Choice` fields was deprecated in Zope 3.2. `iterable` sources were introduced as a simpler alternative. While older usage might still work for compatibility, it's recommended to use sources for new implementations.","severity":"deprecated","affected_versions":"< 3.3.0"},{"fix":"If duplicate values are expected and should be ignored, initialize `Choice` fields (or their underlying vocabularies) with `swallow_duplicates=True`. Example: `zope.schema.Choice(source=my_source, swallow_duplicates=True)`.","message":"`zope.schema.Choice` fields, by default, raise `ValueError` for duplicate values or tokens during vocabulary initialization. If you're building vocabularies from potentially non-pristine data and wish to suppress these errors, you must explicitly set `swallow_duplicates=True` during initialization.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}