Skip to main content

Python Micro check library

Project description

py-check

build codecov Quality Gate Status PyPI - Python Version semantic-release

A general-purpose check library for python. This is a python implementation of part of is.js.

Installation

pip install py-check

Usage

from pycheck import check

check.integer(...)
check.any.integer(...)
check.all.integer(...)

Type Checks

check.integer(value: Any)

Checks if the given value(s) type is integer

interface: all, any

check.integer(123) => True

check.integer(True) => False

check.all.integer(1, 'a') => False

check.any.integer(1, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.integer([1, 2, 3]) => True

check.float(value: Any)

Checks if the given value(s) type is float

interface: all, any

check.float(0.2) => True

check.all.float(0.2, math.inf) => True

check.any.float(0.2, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.float([1.1, 1.2, 2]) => False

check.boolean(value: Any)

Checks if the given value(s) type is boolean

interface: all, any

check.boolean(1) => False

check.all.boolean(True, 1) => False

check.any.boolean(False, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.boolean([True, False]) => True

check.string(value: Any)

Checks if the given value(s) type is string

interface: all, any

check.string('') => True

check.all.string(True, 'a') => False

check.any.string(False, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.string(['True', '1']) => True

check.char(value: Any)

Checks if the given value(s) type is char

interface: all, any

check.char('s') => True

check.all.char(True, 'a') => False

check.any.char(False, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.char(['s', '1']) => True

check.list(value: Any)

Checks if the given value(s) type is list

interface: all, any

check.list([1, 'a']) => True

check.all.list(1, [1, 'a']) => False

check.all.list([1, 2, 3]) => False

check.any.list([], 1) => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.list([1, [1, 2, 3]]) => False

check.dictionary(value: Any)

Checks if the given value(s) type is dictionary

interface: all, any

check.dictionary({}) => True

check.all.dictionary({'a': 1}, 'a') => False

check.any.dictionary({'a': 1}, 'a')

# 'all' and 'any' interfaces can also take argument of list type
check.all.dictionary([{'a': 1}, 'a']) => False

check.set(value: Any)

Checks if the given value(s) type is set

interface: all, any

check.set(set({})) => True

check.set({}) => False

check.all.set({1, 2, 3}, [1, 2, 3]) => False

check.any.set({1 ,2, 3}, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.set([{1, 2, 3}, [1, 2, 3]]) => False

check.tuple(value: Any)

Checks if the given value(s) type is tuple

interface: all, any

check.tuple((1, 2)) => True

check.all.tuple({1, 2}, (1, 2)) => False

check.any.tuple((), 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.tuple([{1, 2}, (1, 2)]) => False

check.none(value: Any)

Checks if the given value(s) type is None

interface: all, any

check.none(None) => True

check.all.none({1, 2}, None) => False

check.any.none(None, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.none([{1, 2}, None]) => False

check.function(value: Any)

Checks if the given value(s) type is function

interface: all, any

check.function(foo) => True

check.all.function({1, 2}, foo) => False

check.any.function(foo, 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.function([{1, 2}, foo]) => False

check.date(value: Any)

Checks if the given value(s) type is date

interface: all, any

check.date(datetime.date(2020, 7, 1)) => True

check.all.date({1, 2}, datetime.date(2020, 7, 1)) => False

check.any.date(datetime.date(2020, 7, 1), 'a') => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.date([{1, 2}, datetime.date(2020, 7, 1)]) => False

check.date_string(value: Any, string_pattern: str = '%Y-%m-%d')

Checks if the given value(s) type is date by string pattern

interface: all, any

check.date('2020-7-1') => True
check.date('2020/7/1', string_pattern='%Y/%m/%d') => True

check.all.date('2020-7-1', '2020-8-1') => True

check.any.date('2020-7-1', 1) => True

# 'all' and 'any' interfaces can also take argument of list type
check.all.date(['2020-7-1', '2020-8-1', 1]) => False

check.same_type(value: Any, *args: Any)

Checks if the given values types are the same

interface: no interface

check.same_type(1) => True

check.same_type(1.1) => True

check.same_type(True, 1) => False

check.same_type(1, False) => False

check.same_type(1, 2, 3) => True

Todo

  • Type Checks
    • check.date
    • check.same_type
  • Presence Checks
    • check.empty
    • check.truthy
    • check.falsy
  • String Checks
    • check.uppercase
    • check.lowercase
    • check.capitalized
  • Integer Checks
    • check.even
    • check.odd
    • check.positive
    • check.negative

Project details


Download files

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

Source Distribution

py-check-1.2.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

py_check-1.2.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file py-check-1.2.0.tar.gz.

File metadata

  • Download URL: py-check-1.2.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for py-check-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2a4ff8bc1d33247358e76a06a30869b3597149005ef3b6d3fd6449bfefd40c02
MD5 b9975e39edb852c7321af587551ca720
BLAKE2b-256 0ad0f0ec339fd3b9f05d439f333c46d016c45f461525496026e0afbfb0d822e0

See more details on using hashes here.

File details

Details for the file py_check-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: py_check-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

File hashes

Hashes for py_check-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 06955bb289e8fa927d014bc9ef6f0de02daf49ab3e8fb677bf18c70a4c4b7603
MD5 93afe45a7267c439aa61c59642140c35
BLAKE2b-256 63bc9e9b5f9e971be2431e5234823ae906d09fd36b37e060ef7cc30e87a78804

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page