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.
pip install zope.schemaVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade your Python environment to 3.9 or later. Refer to the zope.schema PyPI page or documentation for specific version compatibility.
Update your project's packaging configuration to use PEP 420 native namespaces if you encounter import issues after upgrading to 8.0 or higher.
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.
Prefer using `source` arguments with `zope.schema.Choice` fields instead of `vocabulary`. Consult `zope.schema` documentation for examples of creating and using sources.
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)`.
Ensure that a non-None value is assigned to all schema fields defined with `required=True`.
Ensure that values assigned to `zope.schema.Text` fields are always Python strings.
Replace `zope.schema.String` with `zope.schema.Text` when defining a string field in a schema.
Provide a value that is present in the sequence of allowed values defined for the `zope.schema.Choice` field.