Skip to main content
iron-monk logo

iron-monk

Business constraint validation for people who hate data mutation.

The fastest Pure-Python validator. 0 Dependencies. 100% Type-Safe.

PyPI version Python Versions CI/CD Coverage: 100% Zero Dependencies License


📖 Read the official documentation here: benesgarage.github.io/iron-monk


Installation

Install via your preferred package manager:

# Using pip
pip install iron-monk

# Using uv
uv add iron-monk

# Using poetry
poetry add iron-monk

iron-monk uses the monk namespace. Always import monk in your code.

Quickstart

from typing import Annotated
from monk import monk, validate
from monk.constraints import Email, Interval, Len

@monk
class User:
    # No base class, no magic. Just your data.
    email: Annotated[str, Email]
    age:   Annotated[int, Interval(ge=18)]
    tags:  list[Annotated[str, Len(min_len=2)]]   # auto per-element validation

user = User(email="not-an-email", age=12, tags=["a"])
validate(user)  # Aggregates ALL THREE errors. Never fails fast.

When validation fails, iron-monk returns every failure in one structured response:

from monk.exceptions import ValidationError

try:
    validate(user)
except ValidationError as e:
    print(e.errors)
    # [{'field': 'email', 'message': 'Must be a valid email address.', 'code': 'Email'},
    #  {'field': 'age',   'message': 'Must be greater than or equal to 18.', 'code': 'Interval'},
    #  {'field': 'tags[0]', 'message': 'Must have a minimum length of 2.',   'code': 'Len'}]

    print(e.flatten())          # → list[str] for logs
    print(e.to_rfc7807())       # → RFC 7807 problem-detail dict for HTTP APIs

Custom constraints in 3 lines

from monk import constraint

@constraint
class DivisibleBy:
    divisor: int

    def validate(self, value: int) -> None:
        if value % self.divisor != 0:
            raise ValueError(f"Must be divisible by {self.divisor}.")

The Toolkit

A comprehensive suite of built-in constraints — including the kind of complex strings most libraries punt on:

  • CSV — validate comma-separated strings in place, no list allocation
  • Cron — POSIX and AWS EventBridge scheduling strings
  • JWT — structural JWT shape check before passing to a crypto library
  • JSON — verify a string is parsable JSON without mutating it into a dict
  • Not / AnyOf / AllOf — invert and compose any constraint into richer rules

👉 Browse the full catalog →

Performance

iron-monk doesn't compromise on speed.

Tested on Python 3.13, primarily executing 100,000 simple primitive validations.

Metric iron-monk
(v0.25.0)
msgspec
(v0.21.1)
pydantic
(v2.13.4)
attrs
(v26.1.0)
marshmallow
(v4.3.0)
Package Size 0.10 MB 0.44 MB 5.88 MB 0.21 MB 0.17 MB
Cold Start 41.55ms 44.61ms 65.98ms 43.86ms 66.48ms
Object (100k) 0.132s 0.013s 0.053s 0.085s N/A
Dict (100k) 0.092s 0.059s 0.052s N/A 0.452s
Nested Dict (100k) 0.327s 0.072s 0.056s N/A 1.444s
Invalid Dict (100k) 0.246s 0.084s 0.079s N/A 1.045s
Sanitized Dict (100k) 0.103s 0.060s 0.052s N/A 0.429s
Partial Dict (100k) 0.065s N/A N/A N/A 0.275s
Union Dict (100k) 0.120s 0.058s 0.033s N/A N/A
Large List (10k × 1k items) 1.108s 0.057s 0.184s N/A N/A
Refs / Cross-Field (100k) 0.247s N/A N/A N/A N/A
Function Call (100k) 0.176s N/A 0.052s N/A N/A

The Takeaway: Rust-backed libraries win on raw loop speed, but iron-monk is the most efficient choice for the modern cloud. Faster cold starts, zero dependencies, and the only entry on the board that natively handles PATCH updates, payload sanitization, and standalone constraint execution make it the best-in-class validator for AWS Lambda, serverless environments, and CI/CD pipelines where install time and the network round trip are the real bottlenecks.

👉 See our benchmarking methodology →

Why iron-monk

Most validation libraries do too much — they coerce, force you to inherit from a base class, and stop at the first error. iron-monk flips all three.

  • Zero coercion: "123" is never silently rewritten to 123. Wrong format = error.
  • Zero base classes: a @monk class is a plain dataclass. No BaseModel, no metaclass.
  • Zero fail-fast: every field is checked. Get every error in one shot.
  • Annotation is the schema: constraints live inside typing.Annotated. No model layer to keep in sync.

Integrations

iron-monk drops into any modern Python project. Battle-tested recipes for:

  • Strawberry GraphQL — errors-as-data for inputs, Maybe[T] integration
  • Starlette (ASGI) — RFC 7807 exception handlers, dict-mode and DTO-mode handlers
  • SQLAlchemy 2.0 / Tortoise ORM — DTO pattern at the API boundary
  • tyro — validate dataclass-driven CLIs
  • beartype — stack runtime type-checking under business constraints
  • App configuration — fail-fast environment-variable validation on boot

👉 See the recipes →

Feedback

PRs are not currently being accepted (see CONTRIBUTING.md), but bug reports, feature requests, and integration use cases are welcome.

👉 Open an issue →

License

MIT

Metadata

Release files for iron-monk 0.25.1

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

Source distribution (sdist)

Source distribution for iron-monk 0.25.1
File Size Uploaded Provenance Actions
iron_monk-0.25.1.tar.gz 49.2 kB With provenance Details for iron_monk-0.25.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iron-monk 0.25.1
File Interpreter ABI Platform Actions
iron_monk-0.25.1-py3-none-any.whl Python 3 none any Details for iron_monk-0.25.1-py3-none-any.whl

Total release size: 77.1 kB

Release files / iron_monk-0.25.1.tar.gz

Download URL iron_monk-0.25.1.tar.gz
Size 49.2 kB
Tags Source
SHA-256 checksum
How to use checksums
617e60b51e7fd31b836fe3a782b11508ed7726af0f8e00a16cd967a736d55655
BLAKE2b-256 checksum
How to use checksums
467c83ff66167677b4e11f16f8036fda72a728a6ab0548843350b80982521495
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 8, 2026.

Transparency log

Release files / iron_monk-0.25.1-py3-none-any.whl

Download URL iron_monk-0.25.1-py3-none-any.whl
Size 27.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
296d7f347d63273fb6184ca89add49d59572669e1f1017a45b55fbcca697b51a
BLAKE2b-256 checksum
How to use checksums
8be6d106410253a5b68573b702369e08f572b8060992343de0cdbf5c3890c2ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 8, 2026.

Transparency log

Security for iron-monk 0.25.1

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for iron_monk-0.25.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 8, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.25.1 This release

2 release files Full provenance

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