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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: py-check-1.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 d4f404afaa7457e12915e7fc5a4d0932becc83cbeaeb158bb9f84306c9296809
MD5 2b9aa6512177b72cbc55a522c00d2f57
BLAKE2b-256 cc1e022455c58b199ccf2a3af033bf439d867add69a7eb12ccda25fc86b801ad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: py_check-1.2.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8057a443b5e46b32a0cf5d9aced0dd9da165771bc0eef279167b6e42c311ae5b
MD5 17b82756265b6d45864794babd74422b
BLAKE2b-256 4d5d2af2288349570aab98da5e7935120be0defceaf55f59e3f35efdf7d17faf

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