Voluptuous Serialize
Convert Voluptuous schemas to json serializable objects.
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("hobby", default="not specified"): str,
}
)
result = convert(schema)
becomes
(dictionaries become lists to guarantee order of properties)
[
{
"name": "name",
"type": "string",
"lengthMin": 5,
"required": true,
},
{
"name": "age",
"type": "integer",
"valueMin": 18,
"required": true,
},
{
"name": "hobby",
"type": "string",
"default": "not specified",
"required": false,
"optional": true, // This is deprecated. Please use "required" key instead.
}
]
See the tests for more examples.
Custom serializer
You can pass a custom serializer to be able to process custom validators. If the serializer returns UNSUPPORTED, it will return to normal processing.
from typing import Any
from voluptuous_serialize import UNSUPPORTED, UnsupportedType, convert
def custom_convert(value: Any) -> dict[str, str] | UnsupportedType:
if value is my_custom_validator:
return {'type': 'custom_validator'}
return UNSUPPORTED
convert(value, custom_serializer=custom_convert)
Release files for voluptuous-serialize 2.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| voluptuous_serialize-2.7.0.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| voluptuous_serialize-2.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.1 kB
Release files / voluptuous_serialize-2.7.0.tar.gz
| Download URL | voluptuous_serialize-2.7.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d0da959f2fd93c8f1eb779c5d116231940493b51020c2c1026bab76eb56cd09e
|
|
BLAKE2b-256 checksum How to use checksums |
537003a9b61324e1bb8b16682455b8b953bccd1001a28e43478c86f539e26285
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.6
|
Release files / voluptuous_serialize-2.7.0-py3-none-any.whl
| Download URL | voluptuous_serialize-2.7.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee3ebecace6136f38d0bf8c20ee97155db2486c6b2d0795563fafd04a519e76f
|
|
BLAKE2b-256 checksum How to use checksums |
f741d536d9cf39821c35cc13aff403728e60e32b2fd711c240b6b9980af1c03f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.6
|