deal
**Deal** is a Python library for [design by contract][wiki] (DbC) programming.
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 dealuv
uv add dealpoetry
poetry add dealInstalling 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
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
crosshair-toolCrossHair uses symbolic execution and SMT…
permissive · top 15,000 on PyPI
icontracticontract enforces design-by-contract in Python…
permissive · top 15,000 on PyPI
pact-pythonPact Python implements consumer-driven contract…
permissive · top 5,000 on PyPI
python-interfaceDeclares interfaces and statically asserts that…
permissive · top 15,000 on PyPI
DafnyRuntimePythonProvides the Python runtime library needed to…
permissive · top 15,000 on PyPI
zope.interfaceProvides a Python implementation of object…
unclear · top 1,000 on PyPI
eth-brownieBrownie is a Python framework for developing,…
permissive · top 15,000 on PyPI
hypothesisHypothesis is a property-based testing library…
copyleft · top 1,000 on PyPI
dvsimDVSim is a Python-based build and run system…
permissive · top 15,000 on PyPI
datacontract-cliA CLI tool for defining, validating, and…
permissive · top 5,000 on PyPI