$npx skillfedfor your agent

icontract

Provide design-by-contract with informative violation messages.

With conditionsPyPI Quality AssuranceReleased Jan 2026408.3K downloads / mopermissive licensePure Python

Decision gist · record as of 2026-08-14

pure-Python wheel — icontract-2.7.3-py3-none-any.whl
v2.7.3 · released 2026-01-29 · 3 runtime deps: asttokens, contextvars, typing_extensions

Yes, if you want runtime contract enforcement with detailed diagnostics. The permissive MIT license, low install friction, and lack of known vulnerabilities make it safe to adopt. Aging maintenance (197 days since last release) is a minor concern but not a blocker—the library is stable and the repository remains active. Best suited for teams that value explicit contract documentation and detailed failure messages over minimal runtime overhead.AI-flagged interpretation of the facts on this page — verify before relying

Before you install

  • Low friction install with three lightweight runtime dependencies (asttokens, contextvars, typing_extensions).
  • Maintenance status is aging—last release was 197 days ago—but the repository remains active and unarchived with 411 stars.

License · maintenance · safety

permissive license (permissive) — MIT license (permissive) places no restrictions on use, modification, or distribution in proprietary or open-source projects.

last release 2026-01-29 (197 days) · last repo commit 2026-01-29 · 411 stars

0 known vulnerabilities (OSV.dev, 2026-08-14) · 408,319 downloads/mo, #6,881 on PyPI

Verify before relying

pip install icontract

import icontract

@icontract.require(lambda x: x > 3)
def some_func(x: int) -> None:
    pass

some_func(x=5)  # succeeds
some_func(x=1)  # raises ViolationError with details
  • Performance overhead of contract checking at runtime compared to assertion-based alternatives
  • Compatibility with async/await patterns and coroutines
  • Whether inheritance contract weakening/strengthening works correctly with multiple inheritance
Same gist for agents: .md · .json

What it is and what it does

icontract is a Python library that implements design-by-contract through decorators, allowing you to declare preconditions (what must be true before a function runs), postconditions (what must be true after), and invariants (what must always be true for a class). When a contract is violated, it raises a ViolationError with a detailed message that includes the contract condition itself, the values of all relevant variables at the time of violation, and any custom description you provided.

The library is built on three runtime dependencies: asttokens, contextvars, and typing_extensions. It supports Python 3.6 through 3.13 and has been in production use since 2018. Unlike simpler assertion-based approaches, icontract automatically extracts and displays variable values without requiring you to write custom error messages, following the DRY principle. It also supports contract inheritance, allowing subclasses to weaken preconditions and strengthen postconditions.

Use it for

  • Add runtime validation to library APIs to catch misuse early with informative error messages
  • Document and enforce class invariants in complex stateful objects to prevent invalid states
  • Verify function inputs and outputs in data processing pipelines to catch logic errors
  • Generate automated test cases by inferring test strategies from contracts
  • Enforce contracts on HTTP APIs to validate request and response contracts

Worth the install?

AI-flagged interpretation of the facts on this page. Verify before relying on it.

With conditions

Yes, if you want runtime contract enforcement with detailed diagnostics.

The permissive MIT license, low install friction, and lack of known vulnerabilities make it safe to adopt. Aging maintenance (197 days since last release) is a minor concern but not a blocker—the library is stable and the repository remains active. Best suited for teams that value explicit contract documentation and detailed failure messages over minimal runtime overhead.

Install

icontract on PyPI

Before you install

Low friction install with three lightweight runtime dependencies (asttokens, contextvars, typing_extensions). Maintenance status is aging—last release was 197 days ago—but the repository remains active and unarchived with 411 stars.

License in practice

MIT license (permissive) places no restrictions on use, modification, or distribution in proprietary or open-source projects.

Quickstart

pip install icontract

import icontract

@icontract.require(lambda x: x > 3)
def some_func(x: int) -> None:
    pass

some_func(x=5)  # succeeds
some_func(x=1)  # raises ViolationError with details

Verify before relying

  • Performance overhead of contract checking at runtime compared to assertion-based alternatives
  • Compatibility with async/await patterns and coroutines
  • Whether inheritance contract weakening/strengthening works correctly with multiple inheritance

Package facts

Licensepermissive license permissive
Python supportNot specified
Install frictionLow. Pure-Python wheel
Runtime dependencies
3 packages
asttokenscontextvarstyping_extensions
MaintenanceAging 197 days since the last release
Last repo commit
First released
Downloads408,319 / month, #6,881 on PyPI 30-day window, as of 2026-08-14
Known vulnerabilitiesNone known OSV.dev, checked 2026-08-14
Classifiers
Development Status :: 5 - Production/StableIntended Audience :: DevelopersProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Evidence: icontract-2.7.3-py3-none-any.whl

Tags

Capabilities
design by contract pythonprecondition postcondition decoratorcontract validation enforcementpython code contractsassertion with detailed messagesinvariant checking decoratorruntime contract verification
Topics
design-by-contractruntime-validationapi-documentation
PyPI keywords
design-by-contractpreconditionpostconditionvalidation

Let your AI agent find packages like this

Example. Real query, live index.

You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.

wish › “precondition postcondition decorator”

  • icontracticontract enforces design-by-contract in Python through decorators…
  • dealDeal is a Python library for design by contract that adds decorators…
  • pyamgPyAMG provides Algebraic Multigrid (AMG) solvers for efficiently…

Give your agent the search over MCP, or paste the wish link into any chat.

More Quality Assurance packages

coverage Worth it
PyPI · Testing · released Aug 2026

Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.

Install it if you want to measure test completeness or enforce coverage thresholds in your project.

permissive licensepure Python · 3.10+
335.8Mdownloads / mo
ruff Worth it
PyPI · Python Modules · released Aug 2026

Ruff is a Python linter and code formatter written in Rust that combines linting, formatting, and code fixing into a single tool, replacing Flake8, Black, isort, and related utilities.

MITcompiled wheel · 3.7+
316.1Mdownloads / mo
pexpect With conditions
PyPI · Software Development · released Nov 2023

Pexpect spawns and controls interactive console applications by sending input and matching output patterns, automating tasks that would otherwise require manual interaction.

ISCpure Pythonaging
200.8Mdownloads / mo
black Worth it
PyPI · Python Modules · released May 2026

Black reformats Python source code to a consistent style by parsing entire files and rewriting them according to an opinionated, deterministic set of rules, eliminating manual formatting decisions.

MITpure Python · 3.10+
179.9Mdownloads / mo
pytest-xdist Worth it
PyPI · Utilities · released Jul 2025

pytest-xdist distributes pytest tests across multiple CPU cores or machines to speed up test execution, with the simplest usage being `pytest -n auto` to spawn workers equal to available CPUs.

Install it if your test suite takes long enough that parallelization would save meaningful time.

MITpure Python · 3.9+
177.1Mdownloads / mo
cfn-lint Worth it
PyPI · Quality Assurance · released Aug 2026

Validates AWS CloudFormation templates in YAML or JSON format against resource provider schemas and best practices, checking property values and configuration correctness.

Install it if you work with CloudFormation templates.

MIT-0pure Python
114.9Mdownloads / mo

See also deal · crosshair-tool · pact-python · python-interface · overrides · attr · Deprecated · zope.interface · flex · pyvalid