Checker Reference¶
Core¶
is_type¶
-
is_type(obj, type_)[source]¶ Indicate if
objis a type intype_.Hint
This checker is particularly useful when you want to evaluate whether
objis of a particular type, but importing that type directly to use inisinstance()would cause a circular import error.To use this checker in that kind of situation, you can instead pass the name of the type you want to check as a string in
type_. The checker will evaluate it and see whetherobjis of a type or inherits from a type whose name matches the string you passed.Parameters: Returns: Trueifobjis a type intype_. Otherwise,False.Return type:
are_equivalent¶
-
are_equivalent(*args)[source]¶ Indicate if arguments passed to this function are equivalent.
Hint
This checker operates recursively on the members contained within iterables and
dictobjects.Caution
If you only pass one argument to this checker - even if it is an iterable - the checker will always return
True.To evaluate members of an iterable for equivalence, you should instead unpack the iterable into the function like so:
obj = [1, 1, 1, 2] result = are_equivalent(*obj) # Will return ``False`` by unpacking and evaluating the iterable's members result = are_equivalent(obj) # Will always return True
Parameters: args – One or more values, passed as positional arguments. Returns: Trueifargsare equivalent, andFalseif not.Return type: bool
are_dicts_equivalent¶
is_between¶
-
is_between(value, minimum=None, maximum=None)[source]¶ Indicate whether
valueis greater than or equal to a suppliedminimumand/or less than or equal tomaximum.Note
This function works on any
valuethat support comparison operators, whether they are numbers or not. Technically, this means thatvalue,minimum, ormaximumneed to implement the Python magic methods__lte__and__gte__.If
value,minimum, ormaximumdo not support comparison operators, they will raiseNotImplemented.Parameters: - value (anything that supports comparison operators) – The
valueto check. - minimum (anything that supports comparison operators /
None) – If supplied, will returnTrueifvalueis greater than or equal to this value. - maximum (anything that supports comparison operators /
None) – If supplied, will returnTrueifvalueis less than or equal to this value.
Returns: Trueifvalueis greater than or equal to a suppliedminimumand less than or equal to a suppliedmaximum. Otherwise, returnsFalse.Return type: Raises: - NotImplemented – if
value,minimum, ormaximumdo not support comparison operators - ValueError – if both
minimumandmaximumareNone
- value (anything that supports comparison operators) – The
has_length¶
-
has_length(value, minimum=None, maximum=None)[source]¶ Indicate whether
valuehas a length greater than or equal to a suppliedminimumand/or less than or equal tomaximum.Note
This function works on any
valuethat supports thelen()operation. This means thatvaluemust implement the__len__magic method.If
valuedoes not support length evaluation, the checker will raiseNotImplemented.Parameters: - value (anything that supports length evaluation) – The
valueto check. - minimum (numeric) – If supplied, will return
Trueifvalueis greater than or equal to this value. - maximum (numeric) – If supplied, will return
Trueifvalueis less than or equal to this value.
Returns: Trueifvaluehas length greater than or equal to a suppliedminimumand less than or equal to a suppliedmaximum. Otherwise, returnsFalse.Return type: Raises: - TypeError – if
valuedoes not support length evaluation - ValueError – if both
minimumandmaximumareNone
- value (anything that supports length evaluation) – The
is_dict¶
is_string¶
-
is_string(value, coerce_value=False, minimum_length=None, maximum_length=None, whitespace_padding=False)[source]¶ Indicate whether
valueis a string.Parameters: - value – The value to evaluate.
- coerce_value (
bool) – IfTrue, will check whethervaluecan be coerced to a string if it is not already. Defaults toFalse. - minimum_length (
int) – If supplied, indicates the minimum number of characters needed to be valid. - maximum_length (
int) – If supplied, indicates the minimum number of characters needed to be valid. - whitespace_padding (
bool) – IfTrueand the value is below theminimum_length, pad the value with spaces. Defaults toFalse.
Returns: Trueifvalueis valid,Falseif it is not.Return type:
is_iterable¶
-
is_iterable(obj, forbid_literals=(<class 'str'>, <class 'bytes'>), minimum_length=None, maximum_length=None)[source]¶ Indicate whether
objis iterable.Parameters: - forbid_literals (iterable) – A collection of literals that will be considered invalid
even if they are (actually) iterable. Defaults to a
tuplecontainingstrandbytes. - minimum_length (
int) – If supplied, indicates the minimum number of members needed to be valid. - maximum_length (
int) – If supplied, indicates the minimum number of members needed to be valid.
Returns: Trueifobjis a valid iterable,Falseif not.Return type: - forbid_literals (iterable) – A collection of literals that will be considered invalid
even if they are (actually) iterable. Defaults to a
is_not_empty¶
is_none¶
is_variable_name¶
-
is_variable_name(value)[source]¶ Indicate whether
valueis a valid Python variable name.Caution
This function does NOT check whether the variable exists. It only checks that the
valuewould work as a Python variable (or class, or function, etc.) name.Parameters: value – The value to evaluate. Returns: Trueifvalueis valid,Falseif it is not.Return type: bool
is_callable¶
Date / Time¶
is_date¶
is_datetime¶
is_time¶
is_timezone¶
-
is_timezone(value, positive=True)[source]¶ Indicate whether
valueis atzinfo.Caution
This does not validate whether the value is a timezone that actually exists, nor can it resolve timzone names (e.g.
'Eastern'or'CET').For that kind of functionality, we recommend you utilize: pytz
Parameters: - value – The value to evaluate.
- positive (
bool) – Indicates whether thevalueis positive or negative (only has meaning ifvalueis a string). Defaults toTrue.
Returns: Trueifvalueis valid,Falseif it is not.Return type:
Numbers¶
is_numeric¶
-
is_numeric(value, minimum=None, maximum=None)[source]¶ Indicate whether
valueis a numeric value.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
valueis greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
valueis less than or equal to this value.
Returns: Trueifvalueis valid,Falseif it is not.Return type:
is_integer¶
-
is_integer(value, coerce_value=False, minimum=None, maximum=None, base=10)[source]¶ Indicate whether
valuecontains a whole number.Parameters: - value – The value to evaluate.
- coerce_value (
bool) – IfTrue, will returnTrueifvaluecan be coerced to whole number. IfFalse, will only returnTrueifvalueis already a whole number (regardless of type). Defaults toFalse. - minimum (numeric) – If supplied, will make sure that
valueis greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
valueis less than or equal to this value. - base (
int) – Indicates the base that is used to determine the integer value. The allowed values are 0 and 2–36. Base-2, -8, and -16 literals can be optionally prefixed with0b/0B,0o/0O/0, or0x/0X, as with integer literals in code. Base 0 means to interpret the string exactly as an integer literal, so that the actual base is 2, 8, 10, or 16. Defaults to10.
Returns: Trueifvalueis valid,Falseif it is not.Return type:
is_float¶
-
is_float(value, minimum=None, maximum=None)[source]¶ Indicate whether
valueis afloat.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
valueis greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
valueis less than or equal to this value.
Returns: Trueifvalueis valid,Falseif it is not.Return type:
is_fraction¶
-
is_fraction(value, minimum=None, maximum=None)[source]¶ Indicate whether
valueis aFraction.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
valueis greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
valueis less than or equal to this value.
Returns: Trueifvalueis valid,Falseif it is not.Return type:
is_decimal¶
-
is_decimal(value, minimum=None, maximum=None)[source]¶ Indicate whether
valuecontains aDecimal.Parameters: - value – The value to evaluate.
- minimum (numeric) – If supplied, will make sure that
valueis greater than or equal to this value. - maximum (numeric) – If supplied, will make sure that
valueis less than or equal to this value.
Returns: Trueifvalueis valid,Falseif it is not.Return type: