prerequisites
Small runtime validation helpers for preconditions and type checks.
Install
pip install prerequisites
What it provides
- Value checks:
require,require_one_in_all,require_all_in_all - Type checks:
require_type,require_one_of_types,require_all_of_type,require_all_same_type,require_type_or_none - Decorator checks:
@validate_typesfor argument validation using type hints
Quick examples
Value checks
from prerequisites import require, require_all_in_all, require_one_in_all
require(2 > 1)
require_one_in_all([False, True, False])
require_all_in_all([True, 2 + 2 == 4])
Type checks
from prerequisites import (
require_all_of_type,
require_all_same_type,
require_one_of_types,
require_type,
require_type_or_none,
)
require_type(10, int)
require_one_of_types(3.14, (int, float))
require_all_of_type([1, 2, 3], int)
require_all_same_type(["a", "b", "c"], (str,))
require_type_or_none(None, str)
Decorator validation
from prerequisites import validate_types
@validate_types
def add(a: int, b: int) -> int:
return a + b
add(1, 2) # ok
add("1", 2) # raises TypeError
Shallow container behavior
@validate_types validates only outer container types for parameterized hints.
from prerequisites import validate_types
@validate_types
def count(values: list[int]) -> int:
return len(values)
count([1, 2, 3])
count([1, "x"]) # valid in current shallow mode (still a list)
Notes
@validate_typesvalidates function arguments only.- Return annotations are not enforced.
- Errors raise
TypeErrororValueErrordepending on the helper.
Release files for prerequisites 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| prerequisites-1.0.5.tar.gz | 43.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| prerequisites-1.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 49.8 kB
Release files / prerequisites-1.0.5.tar.gz
| Download URL | prerequisites-1.0.5.tar.gz |
|---|---|
| Size | 43.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
54461b7e3a40822ac6b122eed7848c8dcfd19f7c8bf862e197df6ec51441c9a6
|
|
BLAKE2b-256 checksum How to use checksums |
f17e5b5d48fc398601fcd954c66e26a2a5961fdd9ebd91eea2875051b31891e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / prerequisites-1.0.5-py3-none-any.whl
| Download URL | prerequisites-1.0.5-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e9c7ba595ef90312e71f33c864d1f804e9d96c442713c9c7991bf55047a681fb
|
|
BLAKE2b-256 checksum How to use checksums |
d4ae56a5f332058c0dc5f9f876e9ba3257e3a0b1fc3f1a015e1c902d80357792
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|