{"slug": "bringing-formal-verification-to-python-with-temporal-typing", "title": "Bringing Formal Verification to Python with Temporal Typing", "summary": "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.", "body_md": "# Bringing Formal Verification to Python with Temporal Typing\n\nBefore 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.\n\nWith 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.\n\nTo tackle the drift problem, I need a tool that can:\n\n1. Understand the semantics of both Python and TLA+.\n2. Check that the implementation conforms to its specification.\n3. Model-check the specification itself.\n\nWith such a tool, we can formally model our code, verify its correctness within defined model bounds, and detect drift automatically.\n\nThere 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.\n\nYou know what that means. It’s token-burning time.\n\nAfter a week of iteration, **Temporal Typing is live!**\n\n[https://temporal-typing.julin.ai/](https://temporal-typing.julin.ai/)\n\nCheck out this example:\n\n``` python\nfrom typing import Annotated\nfrom temporal_typing import (\n    Ensures, Model, Pure, Requires)\n\ndef split_bill(total: int, n: int) -> Annotated[\n    Pure[tuple[int, ...]],\n    Requires(lambda n: n > 0),\n    Ensures(lambda total, n, result:\n        len(result) == n\n        and sum(result) == total\n        and max(result) - min(result) <= 1),\n]:\n    share, extra = total // n, total % n\n    return tuple(\n        share + 1 if i < extra else share\n        for i in range(n))\n    # return (total // n,) * n  # 🐛\n\nmodel = Model(\n    split_bill, domains={int: range(10)})\n\n# $ ty check ty-tanny.py     ✅ types\n# $ tanny check ty-tanny.py  ✅ logic\n```\n\nThe 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.\n\nUnder 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.\n\nThe 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.\n\nThe 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.\n\n**Type checkers check types. Temporal Typing checkers check behaviour.**\n\nWith 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.\n\nIf you care about the correctness of your Python code, give Temporal Typing a try today!\n\n- Temporal Typing: [https://temporal-typing.julin.ai/](https://temporal-typing.julin.ai/)\n- Tanny: [https://github.com/soasme/tanny](https://github.com/soasme/tanny)\n- Manyan: [https://github.com/soasme/manyan](https://github.com/soasme/manyan)", "url": "https://wpnews.pro/news/bringing-formal-verification-to-python-with-temporal-typing", "canonical_source": "https://julin.ai/2026/12/03/temporal-typing-python/", "published_at": "2026-12-02 11:00:00+00:00", "updated_at": "2026-12-03 09:14:57.519675+00:00", "lang": "en", "topics": ["developer-tools", "ai-tools", "ai-agents"], "entities": ["Temporal Typing", "Tanny", "Manyan", "Julin", "Astral", "ty 1.0", "Pyright", "mypy"], "also_reported_by": [], "takeaway": "Temporal Typing lets Python developers attach Requires, Ensures and Pure annotations to functions and have Tanny translate them to TLA+ for model checking, catching behavioral bugs like a bill-splitting function that passes type checks but violates its spec when the total isn't evenly divisible.", "recommendation": null, "alternates": {"html": "https://wpnews.pro/news/bringing-formal-verification-to-python-with-temporal-typing", "markdown": "https://wpnews.pro/news/bringing-formal-verification-to-python-with-temporal-typing.md", "text": "https://wpnews.pro/news/bringing-formal-verification-to-python-with-temporal-typing.txt", "jsonld": "https://wpnews.pro/news/bringing-formal-verification-to-python-with-temporal-typing.jsonld"}}