Tanny

A static model checker for Python specifications. Tanny reads the Temporal Typing declarations on your Python classes, translates each Model into TLA⁺ with Python's semantics, and checks it in process with Manyan.

  • Nothing executed. Tanny parses source with Ruff's parser: your modules are never imported or run.
  • Python-level counterexamples. A failing trace names Python actions, arguments and state variables.
  • No JVM. One Rust binary with Manyan linked in, on PyPI for Linux and macOS.

Installation#

bash
uv tool install tanny   # or: pip install tanny

At a Glance#

The hour clock of Lamport's Specifying Systems, written with Temporal Typing:

hour_clock.py
from dataclasses import dataclass
from typing import Annotated

from temporal_typing import Action, Init, Invariant, Model, State, prime, spec


@spec(
    init=Init(lambda s: s.hr in range(1, 13)),
    type_ok=Invariant(lambda s: s.hr in range(1, 13)),
)
@dataclass
class HourClock:
    hr: State[int]

    def tick(self) -> Annotated[None, Action(lambda s: prime(s.hr) == (s.hr + 1 if s.hr != 12 else 1))]:
        self.hr = self.hr + 1 if self.hr != 12 else 1


hour_clock_model = Model(HourClock)

Tanny gives each model one verdict. A FAIL comes with the shortest trace that breaks the specification, in Python terms:

bash
$ tanny check examples/
PASS examples/hour_clock.py::hour_clock_model  12 states
FAIL examples/die_hard.py::impl_model  invariant not_solved
    1. init: small=0, big=0
    2. fill_big(): small=0, big=5
    3. pour_big_to_small(): small=3, big=2
    4. empty_small(): small=0, big=2
    5. pour_big_to_small(): small=2, big=0
    6. fill_big(): small=2, big=5
    7. pour_big_to_small(): small=3, big=4

What Tanny Checks#

Failure kindWhat failed
invariant, action-invariantAn Invariant or ActionInvariant in a reachable state or step
propertyA temporal Property, under weak and strong fairness
assumptionAn Assume clause on the constants
conformanceA method body that does not do what its Action, Ensures, frame or return Where says
contractA function contract, for some argument in its domain
refinementA Refines[A] mapping that does not implement A
deadlock, assertion, runtimeA state with no action enabled, a failing assert, or a Python runtime error

Where to Start#