{"id":5051,"library":"schematics","title":"Schematics","description":"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.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/schematics/schematics","tags":["data validation","data structures","serialization","model","schema","api input"],"install":[{"cmd":"pip install schematics","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Historically used for Python 2+3 compatibility. While current versions require Python 3.6+, 'six' might be a vestigial dependency in older dependency trees.","package":"six","optional":true}],"imports":[{"symbol":"Model","correct":"from schematics.models import Model"},{"symbol":"StringType","correct":"from schematics.types import StringType"},{"symbol":"URLType","correct":"from schematics.types import URLType"},{"symbol":"DecimalType","correct":"from schematics.types import DecimalType"},{"symbol":"DateTimeType","correct":"from schematics.types import DateTimeType"},{"symbol":"DataError","correct":"from schematics.exceptions import DataError"}],"quickstart":{"code":"import datetime\nfrom schematics.models import Model\nfrom schematics.types import StringType, DecimalType, DateTimeType\nfrom schematics.exceptions import DataError\n\nclass WeatherReport(Model):\n    city = StringType(required=True)\n    temperature = DecimalType(required=True)\n    taken_at = DateTimeType(default=datetime.datetime.now)\n\n# Create a valid instance\nreport_data = {'city': 'NYC', 'temperature': 80.5}\nt1 = WeatherReport(report_data)\nt1.validate()\nprint(f\"Validated report: {t1.to_primitive()}\\n\")\n\n# Demonstrate validation failure with invalid type\nt_fail_type = WeatherReport({'city': 'LA', 'temperature': 'not-a-number'})\ntry:\n    t_fail_type.validate()\nexcept DataError as e:\n    print(f\"Validation failed (invalid type): {e.messages}\")\n\n# Example with missing required field\nt_missing_field = WeatherReport({'temperature': 75.0})\ntry:\n    t_missing_field.validate()\nexcept DataError as e:\n    print(f\"Validation failed (missing field): {e.messages}\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your Python environment is version 3.6 or higher. Upgrade Python or use a virtual environment configured with a supported Python version.","message":"While 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.","severity":"breaking","affected_versions":"schematics 2.1.1 on Python < 3.6"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All 2.x versions, specifically 2.1.1"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":"schematics 2.1.1 on Python 3.10+"},{"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.","message":"For 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.","severity":"gotcha","affected_versions":"All 2.x versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}