Voluptuous Serialize

2.7.0 · active · verified Tue Apr 14

Voluptuous Serialize is a Python library designed to convert `voluptuous` schemas into dictionaries, making them easily serializable (e.g., to JSON). It is built upon the `voluptuous` data validation library, extending its utility by providing a structured representation of schemas. The current version is 2.7.0, and it appears to have an active release cadence, with the latest version released in August 2025.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a `voluptuous` schema and then use `voluptuous-serialize.convert` to transform it into a dictionary representation. The output is a list of dictionaries, each describing a field in the schema, including its name, type, and validation rules.

import voluptuous as vol
from voluptuous_serialize import convert

schema = vol.Schema({
    vol.Required("name"): vol.All(str, vol.Length(min=5)),
    vol.Required("age"): vol.All(vol.Coerce(int), vol.Range(min=18)),
    vol.Optional("email", default=""): str,
    vol.Optional("tags", default=[]): [str]
})

serialized_schema = convert(schema)
print(serialized_schema)

# Example of output structure (simplified):
# [
#     {'name': 'name', 'type': 'string', 'lengthMin': 5, 'required': True},
#     {'name': 'age', 'type': 'integer', 'valueMin': 18, 'required': True},
#     {'name': 'email', 'type': 'string', 'default': '', 'required': False},
#     {'name': 'tags', 'type': 'array', 'items': {'type': 'string'}, 'default': [], 'required': False}
# ]

view raw JSON →