Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

A painless assertion and validation library for Python.

Project description

version travis coveralls license

Verify is a painless assertion library for Python.


Install using pip:

pip install verify

Verify some value using multiple assertions:

from verify import expect, Not, Truthy, Falsy, Less, Greater

expect(5 * 5,

Verify using your own assert functions:

def is_just_right(value):
    assert value == 'just right', 'Not just right!'

# Passes
expect('just right', is_just_right)

# Fails
    expect('too cold', is_just_right)
except AssertionError:

NOTE: The assert function should return a truthy value, otherwise, expect will treat the falsy return from the function as an indication that it failed and subsequently raise it’s own AssertionError.

Verify using your own predicate functions:

def is_awesome(value):
    return 'awesome' in value

def is_more_awesome(value):
    return value > 'awesome'

expect('so awesome', is_awesome, is_more_awesome)

Verify using chaining syntax:


Verify without expect since the verify assertions can be used on their own:

import verify

# These would pass.
verify.Equal(2, 2)
verify.Greater(3, 2)

# These would fail with an AssertionError
verify.Equal(2, 3)
verify.Greater(2, 3)

If you’d prefer to see assert being used, all verify assertions will return True if no AssertionError is raised:

assert Truthy(1)
assert expect(1, Truthy(), Number())

Multiple Syntax Styles

There are several syntax styles available to help construct more natural sounding assertion chains.

Expect…To Be

Use expect with the to_be aliases. All Pascal case assertions have to_be_* and to_not_be_* prefixes (with a few expections).



Use ensure with is aliases. All Pascal case assertions have is_* and is_not_* prefixes (with a few expections).



Use expect or ensure with the Pascal case assertions.


NOTE: While it’s suggested to not mix styles, each of the assertion syntaxes are available with both expect and ensure. So you can call expect(..).is_int() as well as ensure(..).to_be_int().

Naming Convention Exceptions

As mentioned above, there are some assertions that have nonstandard aliases:

  • Not: not_, does_not, to_fail, and fails
  • Predicate: does, to_pass, and passes
  • All: all_, does_all, and passes_all
  • NotAll: not_all, does_not_all, and fails_all
  • Any: any_, does_any, and passes_any
  • NotAny: not_any, does_not_any, and fails_any
  • Match: to_match, is_match and matches
  • NotMatch: to_not_match, is_not_match and does_not_match
  • Is: to_be and is_
  • Contains: to_contain and contains
  • NotContains: to_not_contain and does_not_contain
  • ContainsOnly: to_contain_only and contains_only
  • NotContainsOnly: to_not_contain_only and does_not_contain_only
  • Length: to_have_length and has_length
  • NotLength: to_not_have_length and does_not_have_length


All of the validators in verify are callables that can be used in two contexts:

  1. By themselves as in Equal(a, b) which will raise an AssertionError if false.
  2. In combination with expect as in expect(a, Equal(b)) which could also raise an AssertionError.

The available validators are:

Validator Description
Truthy Assert that bool(a).
Falsy Assert that not bool(a).
Not Assert that a callable doesn’t raise an AssertionError.
Predicate Assert that predicate(a).
All Assert that all of the list of predicates evaluate a as truthy.
NotAll Assert not All.
Any Assert that any of the list of predicates evaluate a as truthy.
NotAny Assert not Any.
Equal Assert that a == b.
NotEqual Assert not Equal.
Match Assert that a matches regular expression b.
NotMatch Assert not Match.
Is Assert that a is b.
IsNot Assert not Is.
IsTrue Assert that a is True.
IsNotTrue Assert not IsTrue.
IsFalse Assert that a is False.
IsNotFalse Assert not IsFalse.
IsNone Assert that a is None.
IsNotNone Assert not IsNone.
Type Assert that isinstance(a, b).
NotType Assert not Type.
Boolean Assert that isinstance(a, bool).
NotBoolean Assert not Boolean.
String Assert that isinstance(a, (str, unicode)).
NotString Assert not String.
Dict Assert that isinstance(a, dict).
NotDict Assert not Dict.
List Assert that isinstance(a, list).
NotList Assert not List.
Tuple Assert that isinstance(a, tuple).
NotTuple Assert not Tuple.
Date Assert that isinstance(a,
NotDate Assert not Date.
DateString Assert that a matches the datetime format string b.
NotDateString Assert not DateString.
Int Assert that isinstance(a, int).
NotInt Assert not Int.
Float Assert that isinstance(a, float).
NotFloat Assert not Float.
Number Assert that isinstance(a, (int, float, Decimal, long)).
NotNumber Assert not Number.
In Assert that a in b.
NotIn Assert not In.
Contains Assert that b in a.
NotContains Assert not Contains.
ContainsOnly Assert that values from b are the only ones contained in a.
NotContainsOnly Assert not ContainsOnly.
Subset Assert that a is a subset of b.
NotSubset Assert not Subset.
Superset Assert that a is a superset of b.
NotSuperset Assert not Superset.
Unique Assert that a contains unique items.
NotUnique Assert not Unique.
Length Assert that b <= len(a) <= c.
NotLength Assert that not Length.
Greater/GreaterThan Assert that a > b.
GreaterEqual/GreaterOrEqual Assert that a >= b.
Less/LessThan Assert that a < b.
LessEqual/LessOrEqual Assert that a <= b.
Between Assert that b <= a <= c.
NotBetween Assert not Between.
Positive Assert that a > 0.
Negative Assert that a < 0.
Even Assert that a % 2 == 0.
Odd Assert that a % 2 != 1.
Monotone Assert that a is monotonic with respect to b().
Increasing Assert that a is monotonically increasing.
StrictlyIncreasing Assert that a is strictly increasing.
Decreasing Assert that a is monotonically decreasing.
StrictlyDecreasing Assert that a is strictly decreasing.

For more details, please see the full documentation at

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for verify, version 1.1.1
Filename, size File type Python version Upload date Hashes
Filename, size verify-1.1.1-py2-none-any.whl (20.9 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size verify-1.1.1.tar.gz (17.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page