{"id":2220,"library":"pykwalify","title":"pykwalify - JSON/YAML Schema Validator","description":"pykwalify is a Python library and CLI tool for validating JSON and YAML data against a schema, based on the Kwalify schema specification. The current version is 1.8.0, with releases occurring periodically to add features, fix bugs, and update dependencies, though major development seems to have slowed since late 2020.","status":"active","version":"1.8.0","language":"en","source_language":"en","source_url":"https://github.com/grokzen/pykwalify","tags":["validation","schema","yaml","json","kwalify"],"install":[{"cmd":"pip install pykwalify","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Default and preferred YAML parser; minimum version 0.16.0 required since v1.8.0.","package":"ruamel.yaml","optional":false},{"reason":"Required for date/datetime validations; minimum version 2.8.0 required since v1.8.0.","package":"python-dateutil","optional":false}],"imports":[{"note":"The primary validation class 'Core' is typically imported directly from the pykwalify.core submodule for convenience.","wrong":"import pykwalify.core","symbol":"Core","correct":"from pykwalify.core import Core"},{"symbol":"SchemaError","correct":"from pykwalify.errors import SchemaError"},{"symbol":"ValidationError","correct":"from pykwalify.errors import ValidationError"}],"quickstart":{"code":"import io\nfrom pykwalify.core import Core, ValidationError\n\n# Define your schema in YAML\nschema_yaml = \"\"\"\ntype: map\nmapping:\n  name:\n    type: str\n    required: true\n  age:\n    type: int\n    range: {min: 0, max: 120}\n    required: false\n\"\"\"\n\n# Define your data in YAML\ndata_yaml = \"\"\"\nname: Alice\nage: 30\n\"\"\"\n\n# Create Core instance with StringIO objects for schema and data\nc = Core(source_data=io.StringIO(data_yaml), schema_data=io.StringIO(schema_yaml))\n\ntry:\n    c.validate()\n    print(\"Validation successful!\")\nexcept ValidationError as e:\n    print(f\"Validation failed: {e}\")\n\n# Example of invalid data\ninvalid_data_yaml = \"\"\"\nname: Bob\nage: 150\n\"\"\"\nc_invalid = Core(source_data=io.StringIO(invalid_data_yaml), schema_data=io.StringIO(schema_yaml))\n\ntry:\n    c_invalid.validate()\nexcept ValidationError as e:\n    print(f\"Invalid data validation failed as expected: {e}\")\n\n","lang":"python","description":"This quickstart demonstrates how to define a schema and validate YAML data using pykwalify. It uses `io.StringIO` to simulate file input, making the example self-contained. It also shows how to catch `ValidationError` exceptions for invalid data."},"warnings":[{"fix":"Upgrade your Python environment to 3.6 or later.","message":"Python 2.7 and 3.5 support has been dropped. pykwalify v1.8.0 and later require Python 3.6 or newer.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Ensure `ruamel.yaml` (minimum 0.16.0) is installed and used. No code change is typically needed as `pykwalify` defaults to `ruamel.yaml` since v1.8.0.","message":"Support for the `PyYAML` parser has been completely removed in favor of `ruamel.yaml`. Attempts to use `PyYAML` will fail.","severity":"breaking","affected_versions":">=1.8.0"},{"fix":"Update schemas to use `type: bool` for boolean values or ensure data correctly uses `type: int` for numbers.","message":"`True` and `False` are no longer considered valid integers. This change affects schemas where boolean values might have previously passed integer validation.","severity":"gotcha","affected_versions":">=1.5.2"},{"fix":"Install the required versions: `pip install 'ruamel.yaml>=0.16.0' 'python-dateutil>=2.8.0'`.","message":"The default YAML parser was changed to `ruamel.yaml` from `PyYAML` (which was deprecated in 1.5.2 and removed in 1.8.0). Ensure `ruamel.yaml>=0.16.0` and `python-dateutil>=2.8.0` are installed to avoid dependency conflicts or parser issues.","severity":"gotcha","affected_versions":">=1.8.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}