Project description

Background

The problem of sanitizing data (checking correctness and transforming to a
useful form) is widespread throughout programming:

How do I verify user input is correct?

How do I munge data from a spreadsheet into dates and numbers?

How do I convert raw database fields into a programmatic object?

Ian Bicking came up with a sensible idiom for this problem, embodied in his
Formencode library [formencode]: validation and conversion are one and the same
thing, and can be handled by passing raw data through a chain of validators.
Each validator checks and/or transforms the data and passes it on to the next.

In this spirit, konval is a package that provides:

a rich library of validation objects

base classes for easily producing custom validators

functions for easily using validators in a variety of ways

Status

konval is in an exploratory state, having been produced to support another
package and to see if use can be got out of generalising conversion. As such. it
is still an early release and the API may change. Comment is invited.

Installation

The simplest way to install konval is via easy_install[setuptools] or an
equivalent program:

% easy_install konval

Alternatively the tarball can be downloaded [konval-pypi], unpacked and
setup.py run:

% tar zxvf konval.tgz
% cd konval
% python set.py install

konval has no prerequisites and should work with just about any version of
Python.

Using konval

A full API is included in the source distribution.

Examples

Most commonly, konval will be used to check or clean values. Failures result in
exceptions being thrown:

Limitations

konval is aimed at a one-way transformation of data, turning user input or
stored data into Python objects. Certainly it could be used in the reverse
direction, but this is not a primary use case. FormEncode is based around
two-way (round trip) conversion of data, so that may be a useful alternative.

The name konval was chosen because:

there’s already a Python library called “sanity”

out of “valcon”, “valkon”, “conval” etc. it was the one with the fewest hits
on Google

Credit

Thanks to Ian Bicking for inspiration in FormEncode. Thanks also to Egor Ryabkov.