Build Status PyPI version Development Status

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.


Deal in 30 seconds

# the result is always non-negative result: result >= 0)
# the function has no side-effects
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 lint or flake8 to statically check errors.

  • Run python3 -m deal test or pytest to generate and run tests.

  • Just use the function in the project and check errors in runtime.

Read more in the documentation.


python3 -m pip install --user 'deal[all]'


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

  • 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:

Writing contracts