Skip to main content

CheckArg

Guard clause library for Python projects, to validate arguments on every python function/method.

Installation

You can install the latest version of this software from the Python package index (PyPI) as follows:

pip install --upgrade checkarg

Usage

Using CheckArg to validate numbers

In the following example we want to guarantee the first argument is a negative number and the second argument has a positive value or zero:

import checkarg.number as Number

def doSomethingValid(negative_number: int, positive_number: int):
    Number.is_lower(negative_number, 0)
    Number.is_greater_or_equals(positive_number, 0)

    return negative_number, positive_number

Using CheckArg to validate text

The following example requires the string of the first argument has some content, if it is None or empty or whith whitespaces, it will rise an exception. The second argument only requires to not be None or an empty message:

import checkarg.text as Text

def doSomethingValid(title: str, body: str):
    Text.is_not_whitespace(title)
    Text.is_not_empty(body)

    return title, body

Controlling the flow with the exceptions

Whenever the CheckArg detects something wrong it will raise different exceptions by the context. This is an example controling the flow execution:

import checkarg.none_type as NoneType
import checkarg.number as Number
import checkarg.text as Text

from checkarg.exceptions import ArgumentNoneError, ArgumentError, ArgumentOutOfRangeError


def lookup_name(mapping, key: str, default: int):
    try:
        Number.is_greater(default, 0)
    except ArgumentOutOfRangeError:
        return None

    try:
        NoneType.is_not_none(mapping)
    except ArgumentNoneError:
        return default
    
    try:
        Text.is_not_empty(key)
    except (ArgumentError, ArgumentNoneError) as e:
        return default

    return mapping[key]

Contributing

Read the Contributing guidelines

Disclaimer

By sending us your contributions, you are agreeing that your contribution is made subject to the terms of our Contributor Ownership Statement

Maintainers

List of Maintainers

License

MIT

Metadata

Release files for checkarg 0.2.0

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

Source distribution (sdist)

Source distribution for checkarg 0.2.0
File Size Uploaded Provenance Actions
checkarg-0.2.0.tar.gz 5.2 kB Without provenance Details for checkarg-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for checkarg 0.2.0
File Interpreter ABI Platform Actions
checkarg-0.2.0-py3-none-any.whl Python 3 none any Details for checkarg-0.2.0-py3-none-any.whl

Total release size: 12.1 kB

Release files / checkarg-0.2.0.tar.gz

Download URL checkarg-0.2.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4794c48765050f0bab51dcef267d8900cc4da57fc8385290a352467f2240033b
BLAKE2b-256 checksum
How to use checksums
21a200a5178665d02c6c866a7c95c5622fd61cd9608e0e0520819e9bce0f0c4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Release files / checkarg-0.2.0-py3-none-any.whl

Download URL checkarg-0.2.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45fbcd3c6b598fef5bd74d925e8bb4d52c18b84ceb3544882dc0dd4abc34e64c
BLAKE2b-256 checksum
How to use checksums
5491fc1adbdc3418fa147abadbd452a74854ce4c0df7157b079c6a5eaa8babd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

Security for checkarg 0.2.0

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.

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