Skip to content

Commit

Permalink
Rename to voluptuous serialize
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Feb 6, 2018
1 parent fa4fce7 commit 45251bc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
### This is an experiment. Not production ready. Do not use.
# Voluptuous Serialize

# Voluptuous JSON (experiment)

This is an experiment to see if it is possible to easily convert voluptuous schemas to JSON.

Goal would be to create a set of Polymer components that can consume this data and generate a form that matches the expected data.
Convert Voluptuous schemas to dictionaries so they can be serialized.

```python
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
})
from collections import OrderedDict

# Use OrderedDict instead of dict.
# Only starting Python 3.6+ are dictionaries ordered.
schema = OrderedDict()
schema[vol.Required('name')] = vol.All(str, vol.Length(min=5))
schema[vol.Required('age')] = vol.All(vol.Coerce(int), vol.Range(min=18))
schema[vol.Optional('hobby', default='not specified')] = str
schema = vol.Schema(schema)
```

becomes
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from setuptools import setup

setup(name='voluptuous-json',
setup(name='voluptuous-serialize',
version='0.1',
description='Convert voluptuous schemas to JSON',
url='http://github.com/balloob/voluptuous-json',
description='Convert voluptuous schemas to dictionaries',
url='http://github.com/balloob/voluptuous-serialize',
author='Paulus Schoutsen',
author_email='[email protected]',
license='Apache License 2.0',
install_requires=['voluptuous'],
packages=['voluptuous_json'],
zip_safe=True)
zip_safe=True)
2 changes: 1 addition & 1 deletion tests/test_lib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import voluptuous as vol

from voluptuous_json import convert
from voluptuous_serialize import convert


def test_int_schema():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module to convert voluptuous schemas to dictionaries."""
import collections

import voluptuous as vol
Expand All @@ -12,7 +13,7 @@


def convert(schema):
"""Convert a voluptuous schema to JSON."""
"""Convert a voluptuous schema to a dictionary."""
if isinstance(schema, vol.Schema):
schema = schema.schema

Expand Down

0 comments on commit 45251bc

Please sign in to comment.