vtjson

Functions

compile(schema)

Compiles a schema.

make_type(schema[, name, strict, debug, subs])

Transforms a schema into a genuine Python type.

safe_cast(schema, obj)

Validates the given object against the given schema and changes its type accordingly.

validate(schema, obj[, name, strict, subs])

Validates the given object against the given schema.

Classes

Apply([skip_first, name, labels])

Modifies the treatement of the previous arguments in an Annotated schema.

anything()

Matchess anything.

at_least_one_of(*args)

This represents a dictionary with a least one key among a collection of keys.

at_most_one_of(*args)

This represents an dictionary with at most one key among a collection of keys.

close_to(x[, rel_tol, abs_tol])

This matches the real numbers that are close to x in the sense of math.isclose.

comparable(*args, **kwargs)

Base class for objects that are comparable with each other.

compiled_schema()

The result of compiling a schema.

complement(schema)

An object matches the schema complement(schema) if it does not match schema.

cond(*args)

Args is a list of tuples (if_schema, then_schema).

date()

Matches an ISO 8601 date.

date_time([format])

Without argument this represents an ISO 8601 date-time.

div(divisor[, remainder, name])

This matches the integers x such that (x - remainder) % divisor == 0.

domain_name([ascii_only, resolve])

Checks if the object is a valid domain name.

email(**kw)

Checks if the object is a valid email address.

fields(d)

d is a dictionary {"field1": schema1, ...}.

filter(filter, schema[, filter_name])

Applies filter to the object and validates the result with schema.

float_()

Schema that only matches floats.

ge(lb)

This checks if object >= lb.

glob(pattern[, name])

Unix style filename matching.

gt(lb)

This checks if object > lb.

ifthen(if_schema, then_schema[, else_schema])

If the object matches the if_schema then it should also match the then_schema.

intersect(*schemas)

An object matches the schema intersect(schema1, ..., schemaN) if it matches all the schemas schema1, ..., schemaN.

interval(lb, ub[, strict_lb, strict_ub])

This checks if lb <= object <= ub, provided the comparisons make sense.

ip_address([version])

Matches ip addresses of the specified version which can be 4, 6 or None.

keys(*args)

This represents a dictionary containing all the keys in a collection of keys.

lax(schema)

An object matches the schema lax(schema) if it matches schema when validated with strict=False.

le(ub)

This checks if object <= ub.

lt(ub)

This checks if object < ub.

magic(mime_type[, name])

Checks if a buffer (for example a string or a byte array) has the given mime type.

nothing()

Matches nothing.

number()

A deprecated alias for float.

one_of(*args)

This represents a dictionary with exactly one key among a collection of keys.

optional_key(key[, _optional])

Make a key in a Mapping schema optional.

protocol(schema[, dict])

An object matches the schema protocol(schema, dict=False) if schema is a class (or class like object) and its fields are annotated with schemas which validate the corresponding fields in the object.

quote(schema)

An object matches the schema quote(schema) if it is equal to schema.

regex(regex[, name, fullmatch, flags])

This matches the strings which match the given pattern.

set_label(schema, *labels[, debug])

An object matches the schema set_label(schema, label1, ..., labelN, debug=False) if it matches schema, unless the schema is replaced by a different one via the subs argument to validate.

set_name(schema, name[, reason])

An object matches the schema set_name(schema, name) if it matches schema, but the name argument will be used in non-validation messages.

size(lb[, ub])

Matches the objects (which support len() such as strings or lists) whose length is in the interval [lb, ub].

strict(schema)

An object matches the schema strict(schema) if it matches schema when validated with strict=True.

time()

Matches an ISO 8601 time.

union(*schemas)

An object matches the schema union(schema1, ..., schemaN) if it matches one of the schemas schema1, ..., schemaN.

url()

Matches valid urls.

wrapper()

Base class for schemas that refer to other schemas.

Exceptions

SchemaError

Raised if a schema contains an error.

ValidationError

Raised if validation fails.