Skip to main content

typechecks

Check Python values at runtime and raise named errors when arguments have the wrong type. This is a small legacy utility, rather than a static type checker. Python 3.11 or later is required.

Install

python -m pip install typechecks

Check and validate arguments

from typechecks import is_integer, is_string, require_integer, require_string

print(is_string("sample"), is_integer(3))
require_string("sample", name="label", nonempty=True)
require_integer(3, name="count")
try:
    require_string(3, name="label")
except TypeError as error:
    print(type(error).__name__)
True True
TypeError

The is_* functions return booleans. The require_* functions return None on success and raise TypeError for a mismatched type. An empty string with nonempty=True raises ValueError. name labels the argument in the error.

Validate a collection

from typechecks import require_iterable_of

labels = ["tumor", "normal"]
require_iterable_of(labels, str, name="labels")
print("valid")
valid

Use a reusable sequence such as a list: this implementation may traverse the input twice when a value is invalid. It is unsuitable for validating one-shot iterators without first materializing them.

Type semantics

Checks use isinstance(), so subclasses pass. Python booleans are integer subclasses: is_integer(True) returns True, and require_integer(True) succeeds. Integer validation does not check positivity or reject zero; make those value checks in your application.

Use require_instance(value, types, name=...) for another class or a tuple of classes. The API reference gives the actual supported arguments.

Documentation development

Install requirements-docs.txt and run ./docs.sh; execute examples with python scripts/check_docs_examples.py.

Metadata

Release files for typechecks 0.1.2

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

Source distribution (sdist)

Source distribution for typechecks 0.1.2
File Size Uploaded Provenance Actions
typechecks-0.1.2.tar.gz 8.2 kB Without provenance Details for typechecks-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 16.1 kB

Release files / typechecks-0.1.2.tar.gz

Download URL typechecks-0.1.2.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
887e33437ea75d9e6997e8a64419c7f62a68f74ec4bdccd3304544fed35fa310
BLAKE2b-256 checksum
How to use checksums
3d8483860968aeffec2117b4fa45b4a63c3861859d12d06267542178a1837cf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.12

Release files / typechecks-0.1.2-py3-none-any.whl

Download URL typechecks-0.1.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07890048125bcd7f911c0ddf08b47cf4b2bdcf20caa9d7f5a8d62ef20b57ea30
BLAKE2b-256 checksum
How to use checksums
f27d88d69c0ace9b7ed284c32275f08aaebafe0f3197fd6c782805601bd30fe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.12

Security for typechecks 0.1.2

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