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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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