skillfed

deal

**Deal** is a Python library for [design by contract][wiki] (DbC) programming.

deal v4.24.6 97.1K downloads/30d#13,168 on PyPI903
Permissive license AGING released

What it is and what it does

Deal is a design-by-contract library that lets you annotate Python functions with decorators to declare expected behavior: what inputs are valid (preconditions), what outputs must satisfy (postconditions), what invariants must hold, and what side-effects are allowed. Once annotated, the same contract declarations power multiple verification modes—runtime checking, static linting via flake8, property-based test generation, and formal verification—without requiring separate test code. The library has zero runtime dependencies, so you can add contracts during development and leave them enabled or disabled in production.

Deal integrates with pytest, flake8, sphinx, and hypothesis, and supports type annotations. It tracks exceptions and side-effects, detects memory leaks in pure functions, and performs partial execution to statically check possible values. The package has been in production use since 2018 and is actively maintained, though the last release was several months ago.

Use it for:

  • Add precondition and postcondition decorators to functions to catch invalid inputs and outputs early in development.
  • Generate property-based tests automatically from contract decorators using deal.cases() integration.
  • Run static contract checking via flake8 or deal's built-in linter to find violations before runtime.
  • Enforce that functions are pure (no side-effects) and detect unexpected memory retention in pure functions.
  • Formally verify critical code paths to prove correctness for all possible inputs.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Deal is a Python library for design by contract that adds decorators to enforce preconditions, postconditions, invariants, and side-effect tracking, enabling static analysis, property-based testing, and runtime verification.

Yes, with conditions. Deal is worth installing if you want to add design-by-contract discipline to Python code and benefit from both runtime and static verification. The zero-dependency runtime, production track record since 2018, and integration with standard tools (pytest, flake8) make it low-risk to adopt. However, the aging maintenance status (257 days since last release) means you should verify that the version works with your Python version and toolchain before committing to it in a new project.

Install

deal on PyPI

pip

pip install deal

uv

uv add deal

poetry

poetry add deal

Installing deal

Before you install

Low install friction with no runtime dependencies. The package is in production use since 2018 and has 903 repository stars, but maintenance status is aging—last release was 257 days ago.

License in practice

Deal is permissively licensed, allowing use in both open-source and proprietary projects without significant legal constraints.

Quickstart

pip install deal

import deal

@deal.post(lambda result: result >= 0)
@deal.pure
def count(items, item):
    return items.count(item)

test_count = deal.cases(count)

Requires Python 3.8 or later.

Verify before relying

  • Whether the 100% test coverage claim and partial formal verification are current as of version 4.24.6.
  • Performance characteristics and overhead of contract checking at runtime versus static analysis only.
  • Current state of integration with pytest, flake8, sphinx, and hypothesis in this version.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.8)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 257 days since the last release
Last repo commit
First released
Downloads 97,100/month — #13,168 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: deal-4.24.6-py3-none-any.whl

Keywords: deal, contracts, pre, post, invariant, decorators, validation, pythonic, functional

Development Status :: 5 - Production/StableEnvironment :: PluginsIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonTopic :: Software DevelopmentTopic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Quality Assurance

Tags

design by contract decoratorsprecondition postcondition validationpython contract testingside-effect tracking libraryformal verification pythonproperty-based testing frameworkstatic contract checker
design-by-contractformal-verificationtesting-framework

More Software Development packages