{"id":1779,"library":"voluptuous","title":"Voluptuous","description":"Voluptuous is a Python data validation library designed for validating data schemas. It allows defining a desired data structure and then validating input data against that structure, raising detailed exceptions for mismatches. The current version is 0.16.0, and it maintains an active release cadence with regular bug fixes and minor feature additions.","status":"active","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/alecthomas/voluptuous","tags":["validation","schema","data-validation","schema-definition"],"install":[{"cmd":"pip install voluptuous","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"Schema","correct":"from voluptuous import Schema"},{"symbol":"Required","correct":"from voluptuous import Required"},{"symbol":"Optional","correct":"from voluptuous import Optional"},{"symbol":"All","correct":"from voluptuous import All"},{"symbol":"Any","correct":"from voluptuous import Any"},{"symbol":"Coerce","correct":"from voluptuous import Coerce"},{"symbol":"In","correct":"from voluptuous import In"},{"symbol":"Match","correct":"from voluptuous import Match"},{"symbol":"Invalid","correct":"from voluptuous import Invalid"}],"quickstart":{"code":"from voluptuous import Schema, Required, Optional, All, Coerce, In, Match, Invalid\nimport datetime\n\n# Define a schema for user data\nuser_schema = Schema({\n    Required('id'): All(Coerce(int), lambda n: n > 0, msg='ID must be a positive integer'),\n    Required('username', default='guest'): All(str, Match(r'^[a-zA-Z0-9_]+$'), msg='Invalid username'),\n    Optional('email'): All(str, Match(r'^[\\w.-]+@[\\w.-]+\\.[a-zA-Z]{2,}$'), msg='Invalid email format'),\n    Optional('age', default=18): All(Coerce(int), In(range(18, 100)), msg='Age must be between 18 and 99'),\n    Optional('roles', default=['user']): [str],\n    'is_active': Coerce(bool),\n    Optional('created_at', default=lambda: datetime.datetime.now()): Coerce(datetime.datetime)\n})\n\n# Valid data example\nvalid_data = {\n    'id': '123',\n    'username': 'john_doe',\n    'email': 'john@example.com',\n    'age': 30,\n    'is_active': True\n}\n\n# Invalid data example\ninvalid_data = {\n    'id': 0,\n    'username': 'john doe',\n    'age': 'twenty',\n    'is_active': 'yes' # Coerce(bool) is lenient, will be True\n}\n\n# Validate data\ntry:\n    validated_data = user_schema(valid_data)\n    print(\"\\n--- Valid Data Validation ---\")\n    print(\"Original data:\", valid_data)\n    print(\"Validated data:\", validated_data)\n    print(f\"Created at (default):\") # validated_data['created_at']\n\n    print(\"\\n--- Invalid Data Validation ---\")\n    print(\"Original data:\", invalid_data)\n    user_schema(invalid_data) # This will raise an Invalid exception\n\nexcept Invalid as e:\n    print(f\"Validation failed: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to define a schema with required and optional fields, apply various validators (type coercion, regex matching, range checks, custom lambdas), and handle validation errors. It shows how Voluptuous automatically coerces types and handles default values for missing optional fields."},"warnings":[{"fix":"Ensure your project is running on Python 3.9 or a newer compatible version.","message":"Voluptuous dropped support for Python 3.8 in version 0.15.0, and previously dropped Python 3.7 in 0.14.0. The current version (0.16.0) requires Python 3.9 or higher.","severity":"breaking","affected_versions":"0.15.0+"},{"fix":"Upgrade to Voluptuous 0.15.2 or later to get fixes for these interactions.","message":"There were bugs affecting the interaction between `ALLOW_EXTRA` (or `REMOVE_EXTRA`) and the `Any` validator, where extra fields might not be handled as expected or could lead to errors.","severity":"gotcha","affected_versions":"0.15.0, 0.15.1"},{"fix":"Upgrade to Voluptuous 0.14.2 or later to resolve this issue.","message":"A bug existed where `In` and `NotIn` validators could fail when used with unsortable containers (e.g., sets containing mixed types or custom objects without a defined comparison).","severity":"gotcha","affected_versions":"0.12.1 - 0.14.1"},{"fix":"Upgrade to Voluptuous 0.15.1 or later to ensure `Remove` behaves as expected with invalid keys.","message":"The `Remove` marker did not correctly remove keys that failed validation in some scenarios, leading to potentially invalid data remaining after validation attempts.","severity":"gotcha","affected_versions":"0.15.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}