**Deal** is a Python library for [design by contract][wiki] (DbC) programming.
Project Links
Meta
Author: Gram
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
Environment
- Plugins
Intended Audience
- Developers
License
- OSI Approved :: MIT License
Programming Language
- Python
Topic
- Software Development
- Software Development :: Libraries :: Python Modules
- Software Development :: Quality Assurance
A Python library for design by contract (DbC) and checking values, exceptions, and side-effects. In a nutshell, deal empowers you to write bug-free code. By adding a few decorators to your code, you get for free tests, static analysis, formal verification, and much more. Read intro to get started.
Features
- Classic DbC: precondition, postcondition, invariant.
- Tracking exceptions and side-effects.
- Property-based testing.
- Static checker.
- Integration with pytest, flake8, sphinx, and hypothesis.
- Type annotations support.
- External validators support.
- Contracts for importing modules.
- Can be enabled or disabled on production.
- Colorless: annotate only what you want. Hence, easy integration into an existing project.
- Colorful: syntax highlighting for every piece of code in every command.
- Memory leaks detection: deal makes sure that pure functions don't leave unexpected objects in the memory.
- DRY: test discovery, error messages generation.
- Partial execution: linter executes contracts to statically check possible values.
- Formal verification: prove that your code works for all input (or find out when it doesn't).
- Zero-dependency runtime: there are some dependencies for analysis tools, but nothing of it is required on the production.
- Fast: each code change is benchmarked and profiled.
- Reliable: the library has 100% test coverage, partially verified, and runs on production by multiple companies since 2018.
Deal in 30 seconds
# the result is always non-negative
@deal.post(lambda result: result >= 0)
# the function has no side-effects
@deal.pure
def count(items: List[str], item: str) -> int:
return items.count(item)
# generate test function
test_count = deal.cases(count)
Now we can:
- Run
python3 -m deal lintorflake8to statically check errors. - Run
python3 -m deal testorpytestto generate and run tests. - Just use the function in the project and check errors in runtime.
Read more in the documentation.
Installation
python3 -m pip install --user 'deal[all]'
Contributing
Contributions are welcome! A few ideas what you can contribute:
- Add new checks for the linter.
- Improve documentation.
- Add more tests.
- Improve performance.
- Found a bug? Fix it!
- Made an article about deal? Great! Let's add it into the
README.md. - Don't have time to code? No worries! Just tell your friends and subscribers about the project. More users -> more contributors -> more cool features.
To run tests locally, all you need is task. Run task all to run all code formatters, linters, and tests.
Thank you :heart:
4.24.6
Nov 30, 2025
4.24.5
Mar 02, 2025
4.24.4
Mar 23, 2024
4.24.3
Sep 28, 2023
4.24.2
Aug 18, 2023
4.24.1
Mar 24, 2023
4.24.0
Feb 23, 2023
4.23.7
Feb 20, 2023
4.23.6
Feb 12, 2023
4.23.5
Feb 12, 2023
4.23.4
Sep 01, 2022
4.23.3
May 02, 2022
4.23.2
Apr 21, 2022
4.23.1
Apr 12, 2022
4.23.0
Apr 12, 2022
4.22.0
Apr 09, 2022
4.21.2
Apr 09, 2022
4.21.1
Mar 18, 2022
4.21.0
Mar 16, 2022
4.20.0
Mar 01, 2022
4.19.2
Feb 21, 2022
4.19.1
Dec 30, 2021
4.19.0
Dec 03, 2021
4.18.0
Nov 18, 2021
4.17.0
Nov 10, 2021
4.16.0
Nov 05, 2021
4.15.0
Oct 18, 2021
4.14.0
Oct 09, 2021
4.13.0
Oct 07, 2021
4.12.0
Oct 05, 2021
4.11.0
Sep 27, 2021
4.10.0
Sep 24, 2021
4.9.0
Sep 23, 2021
4.8.0
Sep 19, 2021
4.7.3
Sep 19, 2021
4.7.2
Jul 11, 2021
4.7.1
Jul 11, 2021
4.7.0
Jul 08, 2021
4.6.0
May 13, 2021
4.5.0
Dec 27, 2020
4.4.0
Dec 04, 2020
4.3.0
Dec 02, 2020
4.2.0
Oct 15, 2020
4.1.0
Sep 29, 2020
4.0.1
Sep 11, 2020
4.0.0
Sep 11, 2020
3.9.0
May 09, 2020
3.8.1
May 08, 2020
3.8.0
May 01, 2020
3.7.0
Apr 24, 2020
3.6.2
Apr 21, 2020
3.6.1
Apr 20, 2020
3.6.0
Nov 26, 2019
3.5.0
Nov 18, 2019
3.4.0
Nov 14, 2019
3.3.0
Nov 12, 2019
3.2.0
Nov 01, 2019
3.1.0
Oct 04, 2019
3.0.0
Oct 02, 2019
2.4.0
Jul 06, 2019
2.3.0
Jul 05, 2019
2.2.1
Sep 07, 2018
2.2.0
Sep 07, 2018
2.1.0
Jun 10, 2018
2.0.0
Mar 25, 2018
1.2.0
Mar 22, 2018
1.1.0
Feb 04, 2018
1.0.0
Jan 27, 2018
