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

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.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

py_check-1.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py-check-1.1.0.tar.gz
  • Upload date:
  • Size: 5.8 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.1.0.tar.gz
Algorithm Hash digest
SHA256 3a26c7d7c9c906cd1e67c008ba21e442af69608e447834f476876fd6b577d29f
MD5 7df9ff2aa60b6c819f7752e7c6c7b7e4
BLAKE2b-256 7aba44bdc7b6314b86375e50a42a3225b839e9d940469cb4135b803d12d14b91

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_check-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07dfccd6f8423f29a9a5a989242ed676c6bb3567dd6bc8fc140900e6b95a93df
MD5 a488731c1b2825a5792065f667fca269
BLAKE2b-256 4bde0b55223a2e3d9fc54bb14a29ab1d927976ca1f3e83dc038cc8c03583e440

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