skip to navigation
skip to content

Not Logged In

pykwalify 14.08

Python lib/cli for JSON/YAML schema validation

Latest Version: 15.01

# pyKwalify

YAML/JSON validation library

This framework is a port of the java version of the framework kwalify that can be found at:

The source code can be found at:

The schema this library is base and extended from:

# test status

**master branch**: [![Build Status]]

**Coverage - master**: [![Coverage Status]]

# Installation

## Install stable release

Latest stable release from pypi

$ pip install pykwalify

or from source

$ python install

## python dependencies

- docopt 0.6.1
- PyYaml 3.11

## Supported python version

- Python 2.7
- Python 3.2
- Python 3.3
- Python 3.4

# How to test

Install test requirements with

$ pip install -r dev-requirements.txt

Run tests with

$ py.test

or if you want to test against all python versions and pep8

$ tox

# Implemented validation rules

### type

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)

### required

Value is required when true (Default is false). This is similar to not-null constraint in RDBMS.

### enum

List of available values.

### pattern

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``

### regex;(regex-pattern)

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

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

### unique

Value is unique for mapping or sequence.
This is similar to unique constraint of RDBMS.

### name

Name of schema.

### desc

Description is not used for validation.

### allowempty

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.

### matching-rule

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]

### schema;(schema-name)

See ``Partial schemas`` section

### include

See ``Partial schemas`` section

## Partial schemas

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.

type: map
type: str

type: seq
- include: fooone

And it can be used to validate the following data

- foo: opa

# License

MIT [See LICENSE file]

Release Notes


- First version to be uploaded to pypi
- Keyword 'range' can now be applied to map & seq types.
- Added many more test files.
- Keyword 'length' was removed because 'range' can handle all cases now.
- Keyword 'range' now correctly checks the internal keys to be integers
- Major update to testing and increased coverage.


- New feature "partial schema". Define a small schema with a ID that can be reused at other places in the schema. See readme for details.
- New directive "include" that is used to include a partial schema at the specefied location.
- Cli and Core() now can handle multiple schema files.
- Directive "pattern" can no longer be used with map to validate all keys against that regex. Use "regex;" inside "mapping:"
- 'none' can now be used as a type
- Many more tests added


- New version scheme [YY.MM(.Minor-Release)]
- Added TravisCI support
- Update runtime dependency docopt to 0.6.1
- Update runtime dependency pyyaml to 3.11
- Huge refactoring of logging and how it works. Logging config files is now removed and everything is alot simpler
- Cleanup some checks that docopt now handles
- New keyword "regex;<regex-pattern>" that can be used as a key in map to give more flexibility when validating map keys
- New keyword "matching-rule" that can be used to control how keys should be matched
- Added python 3.4 & python 2.7 support (See TravisCI tests for status)
- Dropped python 3.1 support
- Alot of refactoring of testing code.
- Tests should now be runned with "nosetests" and not "python"
- Refactored alot of exceptions to be more specific (SchemaError and RuleError for example) and not a generic Exception
- Parsed rules is now stored correctly in Core() so it can be tested from the outside


- Added new and experimental validation rule allowempty. (See README for more info)
- Added TODO tracking file.
- Reworked the CLI to now use docopt and removede argparse.
- Implemented more typechecks, float, number, text, any
- Now suports python 3.3.x
- No longer support any python 2.x.y version
- Enabled pattern for map rule. It enables the validation of all keys in that map. (See README for more info)
- Alot more test files and now tests source_data and schema_data input arguments to
- Alot of cleanup in the test suit


- Reworked the structure of the project to be more clean and easy to find stuff.
- lib/ folder is now removed and all contents is placed in the root of the project
- All scripts is now moved to its own folder scripts/ (To use the script during dev the path to the root of the project must be in your python path somehow, recomended is to create a virtualenv and export the correct path when it activates)
- New make target 'cleanegg'
- Fixed path bugs in Makefile
- Fixed path bugs in Manifest


- Initial stable release of pyKwalify.
- All functions is not currently implemented but the cli/lib can be used but probably with some bugs.
- This should be considered a Alpha release used for bug and stable testing and to be based on further new feature requests for the next version.
- Implemented most validation rules from the original Java version of kwalify. Some is currently not implemented and can be found via [NYI] tag in output, doc & code.
- Installable via pip (Not the official online pip repo but from the releases folder found in this repo)
- Supports YAML & JSON files from cli and any dict/list data structure if used in lib mode.
- Uses pythons internal logging functionality and default logging output can be changed by changing logging.ini (python 3.1.x) or logging.yaml (python 3.2.x) to change the default logging output, or use -v cli input argument to change the logging level. If in lib mode it uses your implemented python std logging.  
File Type Py Version Uploaded on Size
pykwalify-14.08.tar.gz (md5) Source 2014-08-24 17KB
  • Downloads (All Versions):
  • 12 downloads in the last day
  • 191 downloads in the last week
  • 284 downloads in the last month