Skip to main content

Manages testing for valid kwargs key, values pairs and assigns class attributes for pairs.

Project description

codecov GitHub Workflow Status License MIT PyPI - Python Version PyPI - Wheel Github

kwargshelper

A python package for working with kwargs.

Allows for validation of args passed in via **kwargs in various ways. Such as type checking, rules checking, error handeling.

Many built in rules that make validation of input simple and effective. Easily create and add new rules.

Various callbacks to hook each kwarg with rich set of options for fine control.

Docs

Read the docs here

Installation

You can install the Version Class from PyPI

pip install kwargshelper

KwargsHelper Class

Helper class for working with python **kwargs in a class constructor

Assigns values of **kwargs to an exising class with type checking and rules

Parse kwargs with suport for rules that can be extended that validate any arg of kwargs. Type checking of any type.

Callback function for before update that includes a Cancel Option.

Many other options avaliable for more complex usage.

KwArg Class

Helper class for working with python **kwargs in a method/function Wrapper for KwargsHelper Class.

Assigns values of **kwargs to itself with validation

Parse kwargs with suport for rules that can be extended that validate any arg of kwargs. Type checking of any type.

Callback function for before update that includes a Cancel Option.

Many other options avaliable for more complex usage.

Decorator Classes

Decorators that can applied to function that validate arguments.

Decorators for Type checking and Rule testing is built in.

The following example ensures all function args are a positive int or a positive float.

from kwhelp.decorator import RuleCheckAny
import kwhelp.rules as rules

@RuleCheckAny(rules.RuleIntPositive, rules.RuleFloatPositive)
def speed_msg(speed, limit, **kwargs) -> str:
    if limit > speed:
        msg = f"Current speed is '{speed}'. You may go faster as the limit is '{limit}'."
    elif speed == limit:
        msg = f"Current speed is '{speed}'. You are at the limit."
    else:
        msg = f"Please slow down limit is '{limit}' and you are currenlty going '{speed}'."
    if 'hours' in kwargs:
        msg = msg + f" Current driving hours is '{kwargs['hours']}'"
    return msg

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

kwargshelper-2.7.1.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

kwargshelper-2.7.1-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

Details for the file kwargshelper-2.7.1.tar.gz.

File metadata

  • Download URL: kwargshelper-2.7.1.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for kwargshelper-2.7.1.tar.gz
Algorithm Hash digest
SHA256 b063bd547efdc5b2edff601fe3c3c664dd2359f9fd86681b95d67ed34557d9ca
MD5 56cf22530edc9286a11a48422e3b182e
BLAKE2b-256 500f9adde4b91aac07fc98876723b49deeffcb12e0da970e5cf3dc93366fd412

See more details on using hashes here.

File details

Details for the file kwargshelper-2.7.1-py3-none-any.whl.

File metadata

  • Download URL: kwargshelper-2.7.1-py3-none-any.whl
  • Upload date:
  • Size: 38.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/0.0.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for kwargshelper-2.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78b28f1dc2caf49d1a87c2f906112c58948049223276824fd612928d0ed1f731
MD5 4d1d8c44e6630a091eb45a11936999f1
BLAKE2b-256 18a8fca7346ef5483097b66d46c9947ea9cf155347cdf98f40e175e78987c5a8

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