YAML/JSON validation library
This framework is a port of the java version of the framework kwalify that can be found at: http://www.kuwata-lab.com/kwalify/
The source code can be found at: http://sourceforge.net/projects/kwalify/files/kwalify-java/0.5.1/
The schema used in this library: http://www.kuwata-lab.com/kwalify/ruby/users-guide.01.html#schema
Note: It is recomended allways to use a virtual-enviroment when using pyKwalify
- Download a tar.gz release from https://github.com/Grokzen/pykwalify/releases
- Run
pip install pykwalify-yy.mm.xx.tar.gz
- Run
pykwalify --help
- Clone the repo
- Run
make sdist
- Install with
pip install dist/pykwalify-yy.mm.xx.tar.gz
- Clone the repo
- Run
make install
orpython setup.py install
- docopt 0.6.1
- PyYaml 3.11
- Python 2.7
- Python 3.2
- Python 3.3
- Python 3.4
Install test requirements with
pip install -r dev-requirements.txt
Run tests with with the current python version
py.test
or if you want to test against all python versions run
tox
Type of value. The followings are available:
- str
- int
- float
- bool
- number (int or float)
- text (str or number)
- date [NYI]
- time [NYI]
- timestamp [NYI]
- seq
- map
- none
- scalar (all but seq and map)
- any (means any implemented type of data)
Value is required when true (Default is false). This is similar to not-null constraint in RDBMS.
List of available values.
Specifies regular expression pattern of value. Uses re.match()
Pattern also works on all scalar types.
Pattern no longer works in map. Use regex;(regex-pattern)
as keys in mapping
This is only implemented in map where a key inside the mapping keyword can implement this regex;(regex-pattern)
pattern and all keys will be matched against the pattern.
If a match is found then it will parsed the subrules on that key. A single key can be matched against multiple regex rules and the normal map rules.
Range of value between max / max-ex
and min / min-ex
.
max
means 'max-inclusive'. (a >= b)min
means 'min-inclusive'. (a <= b)max-ex
means 'max-exclusive'. (a > b)min-ex
means 'min-exclusive'. (a < b)
This works with map, seq, str, int
Type bool and any are not available with range
Value is unique for mapping or sequence. This is similar to unique constraint of RDBMS.
Name of schema.
Description is not used for validation.
NOTE: Experimental feature!
Only applies to map. It enables a dict to have items in it that is not validated. It can be combined with mapping to check for some fixed properties but still validate if any random properties exists. See example testfile 18a, 18b, 19a, 19b.
NOTE: Experimental feature!
Only applies to map. This enables more finegrained control over how the matching rule should behave when validation keys inside mappings.
Currently supported rules is
- any [This will match any number of hits, 0 to n number of hits will be allowed]
See Partial schemas
section
See Partial schemas
section
It is possible to create small partial schemas that can be included in other schemas. This feature do not use any built-in YAML or JSON linking.
To define a partial schema use the keyword schema;(schema-id):
. (schema-id)
must be globally unique for the loaded schema partials. If collisions is detected then error will be raised.
To use a partial schema use the keyword include: (schema-id):
. This will work at any place you can specify the keyword type
. Include directive do not currently work inside a partial schema.
It is possible to define any number of partial schemas in any schema file as long as they are defined at top level of the schema.
For example, this schema contains one partial and the regular schema.
schema;fooone:
type: map
mapping:
foo:
type: str
type: seq
sequence:
- include: fooone
And it can be used to validate the following data
- foo: opa
MIT [See LICENSE file]