Registry / serialization / zope-schema

zope-schema

JSON →
library8.1pypypi✓ verified 21d ago

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.schema
INSTALL
IMPORT
SIG · ZOPE-SCHEMA
Z
zope-schema
serializationpythonv8.1
Install
1.9s avg
Import
24ms
Disk
19MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.026s · 20.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.9s · import 0.022s · 21MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Interface
from zope.interface import Interface
TextLine
from zope.schema import TextLine
URI
from zope.schema import URI
Bool
from zope.schema import Bool
Choice
from zope.schema import Choice

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.

import zope.interface import zope.schema class IBookmark(zope.interface.Interface): title = zope.schema.TextLine( title='Title', description='The title of the bookmark', required=True ) url = zope.schema.URI( title='Bookmark URL', description='URL of the Bookmark', required=True ) @zope.interface.implementer(IBookmark) class Bookmark(object): title = None url = None bm = Bookmark() # Example of validation (a common use case) try: IBookmark['title'].validate('My Awesome Bookmark') IBookmark['url'].validate('http://example.com/bookmark') print("Validation successful!") except zope.schema.ValidationError as e: print(f"Validation failed: {e}")
Debug
Known issues
breakingPython 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.
fix
Upgrade your Python environment to 3.9 or later. Refer to the zope.schema PyPI page or documentation for specific version compatibility.
affects: 7.0.0, 7.1.0
breakingThe `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.
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.
affects: 8.0.0
gotchaIn 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.
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.
affects: 6.1.0, 6.1.1
deprecatedThe 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.
fix
Prefer using `source` arguments with `zope.schema.Choice` fields instead of `vocabulary`. Consult `zope.schema` documentation for examples of creating and using sources.
affects: < 3.3.0
gotcha`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.
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)`.
affects: All
Errors
Common errors & fixes
zope.schema.Invalid: Missing required value
A value was not provided for a field in the schema that was marked as 'required=True'.
fix
Ensure that a non-None value is assigned to all schema fields defined with `required=True`.
TypeError: ('value is not a text string', ...)
An attempt was made to assign a non-string value (e.g., an integer or boolean) to a `zope.schema.Text` field.
fix
Ensure that values assigned to `zope.schema.Text` fields are always Python strings.
AttributeError: module 'zope.schema' has no attribute 'String'
The `zope.schema` library uses `Text` for string fields, not `String`, which is a common misconception.
fix
Replace `zope.schema.String` with `zope.schema.Text` when defining a string field in a schema.
zope.schema.Invalid: Value not in list of values
The value provided for a `zope.schema.Choice` field was not among the options specified in its `values` or `source` parameter.
fix
Provide a value that is present in the sequence of allowed values defined for the `zope.schema.Choice` field.
Upgrade
Version history
8.1latest on PyPI · released Oct 26, 2025
Audit
Dependencies
zope.interfacerequiredzope.schema builds upon zope.interface to define schemas as extended interfaces.
Agent activity
53 hits · last 30 days
node
44
OpenAI (training)
1
Resources
zope-schema — pip install zope-schema · libregistry