Skip to main content

Python Parameter Verification

Homepage: https://www.learningtopi.com/python-modules-applications/parameter_verification/

This is a simple Python function that can be used to test variable types and values. The intended purpose is to check the parameters of a function to ensure that appropriate types and values have been passed.

The function is specifically written to support Python >=3.3 so it can be used with a wide array of applications. There are also no dependencies that need to be installed.

Usage

from parameter_verification import verify_params, ParameterError

def test_function_1(param1, param2, param3, param4):
    ''' Sample function to show verify_params usage '''
    try:
        verify_params(param1=(param1,int), param2=(param2,str,'=abc'), param3=(param3,float, '>100.2', '<110.0'), param4=(param4,str,'len=4','=abcd'))
    except ParameterError as e:
        # some code to handle an exception if desired

    # proceed with your function!

The verify_param function takes keyword arguments for each parameter to check. The value of each parameter is passed as a tuple consisting of:

  • The value to check (i.e. the variable)
  • The variable type to check against
  • (optional) an additional check to perform (i.e. '>100.2' or '=abc')
  • (optional) more additional checks can be added, i.e. '>100.2', '<110.0'

Supported Checks

The following checks are supported (in addition to the data type which can be any Python type):

  • '==' or '=': Both perform the same check and can be used interchangably
  • '<', '<=', '>', '>=': Perform the typical checks
  • 'len=x', 'len>x', 'len>=x', etc: Check the length of a string

Returns and Errors

The function returns True if all parameters pass. If a parameter check fails, the function raises a ParameterError exception. If desired, this behavior can be changed by setting "no_raise=True". With no_raise set to True, False will be returned in the case of a failed parameter check rather than raising an exception.

Metadata

Release files for parameter-verification 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for parameter-verification 0.1.1
File Size Uploaded Provenance Actions
parameter_verification-0.1.1.tar.gz 4.1 kB Without provenance Details for parameter_verification-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for parameter-verification 0.1.1
File Interpreter ABI Platform Actions
parameter_verification-0.1.1-py3-none-any.whl Python 3 none any Details for parameter_verification-0.1.1-py3-none-any.whl

Total release size: 8.7 kB

Release files / parameter_verification-0.1.1.tar.gz

Download URL parameter_verification-0.1.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
77e68372024ff5004241994f2c3b7eb101f2ca84addd5f91f92a738cf8768452
BLAKE2b-256 checksum
How to use checksums
fac91f465b2a7e8d95ab56f7617468a11c5ce4b04eea3a3198a174990f926a5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / parameter_verification-0.1.1-py3-none-any.whl

Download URL parameter_verification-0.1.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a8d410f905d3ef1690501396de5d351ccc00eddd174b8fafb3243a1c0be00f2
BLAKE2b-256 checksum
How to use checksums
87e413616b077945baa89fb12c43b20e1e9897bb148bb906a0c9d471735bbcb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Security for parameter-verification 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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