Registry / serialization / schematics

schematics

JSON →
library2.1.1pypypi✓ verified 21d ago

Schematics is a Python library for defining, validating, and transforming data structures. It allows combining types into structures, validating them, and transforming data shapes based on simple descriptions, similar to ORM type systems but without a database layer. The current stable version is 2.1.1. While there isn't a strict, regular release cadence, the library has seen active development and maintenance, offering an intuitive API and comprehensive features for modern Python applications.

pip install schematics
INSTALL
IMPORT
SIG · SCHEMATICS
S
schematics
serializationpythonv2.1.1
Install
1.7s avg
Import
222ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.1.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.228s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.216s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

Model
from schematics.models import Model
StringType
from schematics.types import StringType
URLType
from schematics.types import URLType
DecimalType
from schematics.types import DecimalType
DateTimeType
from schematics.types import DateTimeType
DataError
from schematics.exceptions import DataError

This quickstart defines a `WeatherReport` model with city (required string), temperature (required decimal), and a default `taken_at` (datetime). It demonstrates successful model instantiation and validation, along with catching `DataError` exceptions for invalid data types and missing required fields.

import datetime from schematics.models import Model from schematics.types import StringType, DecimalType, DateTimeType from schematics.exceptions import DataError class WeatherReport(Model): city = StringType(required=True) temperature = DecimalType(required=True) taken_at = DateTimeType(default=datetime.datetime.now) # Create a valid instance report_data = {'city': 'NYC', 'temperature': 80.5} t1 = WeatherReport(report_data) t1.validate() print(f"Validated report: {t1.to_primitive()}\n") # Demonstrate validation failure with invalid type t_fail_type = WeatherReport({'city': 'LA', 'temperature': 'not-a-number'}) try: t_fail_type.validate() except DataError as e: print(f"Validation failed (invalid type): {e.messages}") # Example with missing required field t_missing_field = WeatherReport({'temperature': 75.0}) try: t_missing_field.validate() except DataError as e: print(f"Validation failed (missing field): {e.messages}")
Debug
Known issues
breakingWhile older documentation mentions support for Python 2.7 and Python 3.3-3.7, the latest `schematics` 2.1.1 explicitly declares `requires_python: >=3.6` on PyPI. Attempting to install or run this version on older Python versions (e.g., Python 2.x, 3.3, 3.4, 3.5) will result in installation failures or runtime errors due to dropped compatibility.
fix
Ensure your Python environment is version 3.6 or higher. Upgrade Python or use a virtual environment configured with a supported Python version.
affects: schematics 2.1.1 on Python < 3.6
gotchaThe official documentation for Schematics (e.g., on Read the Docs) explicitly states that it is 'currently somewhat out of date.' This can lead to discrepancies between the documented behavior, available features, or best practices and the actual state of the 2.1.1 release.
fix
For critical information, complex use cases, or troubleshooting, cross-reference the documentation with the library's GitHub issues, PyPI description, and the source code for the most current and accurate details.
affects: All 2.x versions, specifically 2.1.1
gotchaWhen running on Python 3.10 and newer, `schematics` may emit `DeprecationWarning` messages, typically related to deprecated imports from `collections.abc` (e.g., `collections.Iterable`). While these are currently warnings, they indicate usage of Python APIs that are slated for removal in future Python versions (e.g., Python 3.12+), which could eventually lead to breaking errors.
fix
Monitor the `schematics` GitHub repository for updates that address these deprecations. For now, acknowledge the warnings; if they are disruptive in non-critical environments, consider temporarily suppressing `DeprecationWarning`s, but be aware of the potential for future compatibility issues.
affects: schematics 2.1.1 on Python 3.10+
gotchaFor handling validation failures, `schematics.exceptions.DataError` is the general exception to catch for all validation-related issues from models. While some older examples or specific scenarios might refer to `schematics.exceptions.ModelValidationError`, `ModelValidationError` is a subclass of `DataError`. Using `DataError` ensures you catch all relevant validation exceptions consistently.
fix
Always catch `schematics.exceptions.DataError` to handle general model validation failures, as it acts as the base class for other, more specific validation exceptions.
affects: All 2.x versions
Upgrade
Version history
2.1.1latest on PyPI · released Aug 17, 2021
Audit
Dependencies
sixoptionalHistorically used for Python 2+3 compatibility. While current versions require Python 3.6+, 'six' might be a vestigial dependency in older dependency trees.
Agent activity
6 hits · last 30 days
node
4
OpenAI (training)
1
Resources
schematics — pip install schematics · libregistry