Skip to main content

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.

GitHub License Contributors
GitHub commit activity Last Commit
Code Style: Ruff Linter: Ruff

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:

  1. Install via pip:
pip install ironclad
  1. 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

See the contributing page.

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)

Source distribution for ironclad 0.1.0
File Size Uploaded
ironclad-0.1.0.tar.gz 20.3 kB Details

Built distribution (wheel)

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

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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