ironclad
ironclad helps developers write defensive, self-documenting Python code.
It enforces parameter types, constrains values with predicates or enums, and raises precise errors on violation—keeping interfaces explicit and code clean. Simple, composable guards harden functions and classes with correctness and security, with minimal overhead and maximum readability.
Features
- Strict type checks: Fail fast on mismatches with clear
TypeErrors. - Value constraints: Allowlists, enums, ranges, and custom predicates.
- Composable guards: Combine checks for rich, readable contracts.
- Low-boilerplate API: Keep validation close to the signature, not scattered.
- Security-minded: Reduce attack surface from unexpected inputs.
Installation
You can install ironclad in one of two ways:
- Install via pip:
pip install ironclad
- Clone this repository:
git clone https://github.com/Zentiph/ironclad
Quick Start
Importing the library:
>>> import ironclad as ic
Ensuring strict type enforcements on functions:
>>> # enforcing types with instance/type spec checks
>>> @ic.enforce_types(price=float, tax_rate=float)
... def add_sales_tax(price, tax_rate):
... return price * (1 + tax_rate)
...
>>> add_sales_tax(50.0, 0.08)
54.0
>>> add_sales_tax(50.0, "0.08")
TypeError: add_sales_tax(): 'tax_rate' expected 'float', got 'str' with value '0.08'
>>>
>>> # enforcing types with type annotations
>>> @ic.enforce_annotations()
... def get_even(l: list[int]) -> list[int]:
... return [e for e in l if e % 2 == 0]
...
>>> get_even([1, 2, 3])
[2]
>>> get_even([1.0, 2.0, 3.0])
TypeError: get_even(): 'l' expected 'list[int]', got 'list' with value [1.0, 2.0, 3.0]
Creating type-enforced runtime overloads:
>>> @ic.runtime_overload
... def describe(x: int):
... return f"int: {x}"
...
>>> @describe.overload
... def _(x: str):
... return f"str: '{x}'"
...
>>> describe(1)
'int: 1'
>>> describe("hi")
"str: 'hi'"
>>> describe(2.3)
InvalidOverloadError: No overload of describe() matches (float). Candidates: describe(x: int) | describe(x: str)
Creating predicates
>>> is_pos = ic.predicates.Predicate[int](
... lambda x: x > 0, "is positive"
... )
>>> is_pos(4)
True
>>> is_pos(-1)
False
Documentation
ironclad's documentation is deployed on GitHub Pages.
Contributions
License
See the license page.
Metadata
Release files for ironclad 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ironclad-0.1.0.tar.gz | 20.3 kB | Without provenance | Details for ironclad-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ironclad-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for ironclad-0.1.0-py3-none-any.whl |
Total release size: 47.4 kB
Release files / ironclad-0.1.0.tar.gz
| Download URL | ironclad-0.1.0.tar.gz |
|---|---|
| Size | 20.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e0d43950ee70922a4b13274ad39f33bc70c784e7a5ac2e76efec6f689149ad8a
|
|
BLAKE2b-256 checksum How to use checksums |
d79792d216d293cae030096bc24da8d2a53ff1a3f9b96025e27a2e1b2f09b6df
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Release files / ironclad-0.1.0-py3-none-any.whl
| Download URL | ironclad-0.1.0-py3-none-any.whl |
|---|---|
| Size | 27.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a8e42816e4c30ae8aa4b06bee770809d516af4226ed5a1ce3044ae7e5ecae1bf
|
|
BLAKE2b-256 checksum How to use checksums |
3d1854060b275d3e6c0bd35487d1fdac5adccb6f3bc5de345fc3075f9b5d672b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.9
|
Security for ironclad 0.1.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.