Skip to main content

KWCHECKER a verifier and sanitizer for python kwargs parameters

The kwchecker package simplifies validation & sanitation of python kwargs parameter, your can define most validations declaratively, in a map. See the following example, where the validator definitions are passed to the kwchecker.KwArgsChecker constructor.

        def func_to_test(**kwargs):
            checker = kwchecker.KwArgsChecker(required={
                    "first_name": (
                        str,
                        kwchecker.no_regex_validator("^\s*$", "Error: empty first name"),
                        kwchecker.strip_leading_trailing_space(),
                        kwchecker.capitalize_first_letter(),
                    ),
                    "last_name": (
                        str,
                        kwchecker.no_regex_validator(r"^\s*$", "Error: empty last name"),
                        kwchecker.strip_leading_trailing_space(),
                        kwchecker.capitalize_first_letter(),
                    ),

                    "title" : str,

                    "email" : kwchecker.email_validator(),

                    "phone" : (
                        kwchecker.regex_validator(r"^[0-9\+\-,\ \(\)#]*$", "not a vald phone number")
                        )
                }, opt={
                    "mood": kwchecker.int_range_validator(0, 10),
                    "plan": str
                })

            checker.validate(kwargs)

The constructor has two arguments required receives the definition for mandatory parameters passed via kwargs, opt receives definitions of optional parameters. An errror is triggered, if an actual parameter in kwargs does not appear in any of these definitions.]

Each allowed parameter name appears as a key in the dictionary arguments. The value of the entry defines the actual validation/sanitation. A type value will check, if the supplied argument is of the requested type

"title" : str - this will check if the kwargs parameter title is of type string.

A funcion value will be either a validation function, or a sanitier function.

"email" : kwchecker.email_validator() - this validates that the email parameter in kwargs is a valid email address. Note that function email_validator is being called here, as it returns a closure.

You may pass a tuple of values that are either types or functions. see

"last_name": (
    str,
    kwchecker.no_regex_validator(r"^\s*$", "Error: empty last name"),
    kwchecker.strip_leading_trailing_space(),
    kwchecker.capitalize_first_letter(),
)

The action for the kwargs last_name parameter will first verify that parameter to be of type string, then it will verify, that the value is not an empty string kwchecker.no_regex_validator(r"^\s*$", "Error: empty last name"), then it will strip the leading and trailing whitespaces kwchecker.strip_leading_trailing_space(), and capitalize the first letter of the value kwchecker.capitalize_first_letter()

Download files

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

Source Distribution

kwchecker-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kwchecker-1.0.0-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file kwchecker-1.0.0.tar.gz.

File metadata

  • Download URL: kwchecker-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for kwchecker-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d567c04c4daf233929c885fde186366cf9fa6f59b6c6ab971ec46aa8c1964e22
MD5 e2437211a31fb86f50ea5a9f7922ac96
BLAKE2b-256 54c55d9e502fa838ebdf61cd1bc1fe64f314c0b676995d0b3f5f20b5cc1340ef

See more details on using hashes here.

File details

Details for the file kwchecker-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kwchecker-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for kwchecker-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 801f4fb881f0c4511544b1f6c8b430ecd1a25206eab095c6751e27e01a3326cd
MD5 ab61160a2b18589af1b4b09c9daff739
BLAKE2b-256 87aec2c63adaa6ce5e078c38dc0ada854a7fa5cec64a59790a1ce3c526bf64d2

See more details on using hashes here.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

This release

1.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page