Skip to content

Quickstart

This page shows the core Tython style and rules you need to write code correctly.

First Program

const MAX_USERS: int = 100
var count = 0

if true {
    count = count + 1
}

Mental Model

  • Declare every name before use.
  • Choose mutability at declaration time:
  • const = cannot be reassigned
  • var = can be reassigned
  • Use explicit lexical blocks.
  • Avoid shadowing and implicit behavior.

Syntax Highlights

  • Lowercase literals: true, false, none
  • Typed list annotations: str[], int[], Fish[]
  • Explicit blocks with braces: if ... { ... }
  • Functions use func keyword
  • Records and classes:
  • record for immutable named shapes
  • class for stateful behavior with init + optional setup
func add(a: int, b: int) -> int {
    return a + b
}

Run and Transpile

Run tests:

uv run python -m pytest

Run a .ty file (project mode):

uv run tython init --name my_app
uv run tython run
uv run tython run src/main.ty

Transpile .ty to Python:

uv run tython transpile input.ty output.py