Bringing Formal Verification to Python with Temporal Typing Developer Julin launched Temporal Typing, a Python library that expresses formal specifications through standard type annotations using Pure, Requires, Ensures and Model, and verifies implementations against them. Its default checker, Tanny, statically analyzes Python source, translates both the specification and the implementation into TLA+, and model-checks them with Manyan without executing the Python code. The annotations remain compatible with Pyright, mypy and ty 1.0, released by Astral this week, and the tool catches bugs that conventional type checkers accept, such as a bill-splitting function that returns a tuple of integers but violates its specification when the total is not evenly divisible. Bringing Formal Verification to Python with Temporal Typing Before the rise of coding agents, I used to hand-craft TLA+ specs for my beloved projects and write implementations based on those models. However, that workflow was fragile. I could get the implementation wrong, and whenever I updated the specs or the implementation, I had to keep both in mind to stop them from drifting apart. With state-of-the-art models, such a translation now costs almost nothing okay, except for tokens . Nonetheless, the process is still fragile. I’ve run into several cases where Claude Code translated TLA+ specs into Python code incorrectly, making the same mistakes I used to make in the old days. To tackle the drift problem, I need a tool that can: 1. Understand the semantics of both Python and TLA+. 2. Check that the implementation conforms to its specification. 3. Model-check the specification itself. With such a tool, we can formally model our code, verify its correctness within defined model bounds, and detect drift automatically. There are a few interesting projects in other languages, such as LemmaScript TypeScript and Kani Rust . But I couldn’t find quite what I wanted in the Python world. You know what that means. It’s token-burning time. After a week of iteration, Temporal Typing is live https://temporal-typing.julin.ai/ https://temporal-typing.julin.ai/ Check out this example: python from typing import Annotated from temporal typing import Ensures, Model, Pure, Requires def split bill total: int, n: int - Annotated Pure tuple int, ... , Requires lambda n: n 0 , Ensures lambda total, n, result: len result == n and sum result == total and max result - min result <= 1 , : share, extra = total // n, total % n return tuple share + 1 if i < extra else share for i in range n return total // n, n 🐛 model = Model split bill, domains={int: range 10 } $ ty check ty-tanny.py ✅ types $ tanny check ty-tanny.py ✅ logic The code uses Annotated , introduced in PEP 593 https://peps.python.org/pep-0593/ . The declarations Pure , Requires , Ensures , and Model express formal specifications through ordinary Python type annotations. Under the hood, the default checker, Tanny https://github.com/soasme/tanny , statically analyzes the Python source code, translates both the specification and the implementation into TLA+, and model-checks them with Manyan. It does all of this without executing the Python code. The interesting part is that both the correct and the buggy implementations are valid from a conventional type checker’s perspective. Both return a tuple of integers. But the buggy one violates the specification whenever the bill cannot be divided evenly. The annotations are compatible with existing type checkers such as Pyright, mypy, and even ty 1.0, released by the Astral team this week. Temporal Typing adds another layer of semantics to these annotations, so model checkers can verify the behaviour of the code, not just its types. Type checkers check types. Temporal Typing checkers check behaviour. With coding agents making code ever cheaper to produce, I believe formal verification should become part of our everyday development workflow, just like type checking, linting, and testing. If you care about the correctness of your Python code, give Temporal Typing a try today - Temporal Typing: https://temporal-typing.julin.ai/ https://temporal-typing.julin.ai/ - Tanny: https://github.com/soasme/tanny https://github.com/soasme/tanny - Manyan: https://github.com/soasme/manyan https://github.com/soasme/manyan