Meet the language.
Write typed .ty source, check it with tyc and build readable Python. These are the language rules and the code you deploy.
What you deploy is Python
The compiler writes readable Python for CPython 3.13+: dataclasses, PEP 695 generics, match and asyncio. You do not install the compiler in production. Features such as Result generate Python helpers alongside your output.
async def dashboard(uid: UserId) -> str:
gather:
user = fetch_user(uid)
posts = fetch_posts(uid)
return f"{user.name}: {len(posts)} posts"async def dashboard(uid: UserId) -> str:
async with asyncio.TaskGroup() as __typhon_tg_0__:
__typhon_gather_1__ = __typhon_tg_0__.create_task(fetch_user(uid))
__typhon_gather_2__ = __typhon_tg_0__.create_task(fetch_posts(uid))
user = __typhon_gather_1__.result()
posts = __typhon_gather_2__.result()
return f"{user.name}: {len(posts)} posts"Real output from tyc 1.0.0-beta.7. gather: runs independent awaits on a TaskGroup, so if one fails the rest are cancelled. View the complete example, including its types and functions.
def configure(raw_port: str) -> Result[int, str]:
let port: int = parse_port(raw_port)?
return Ok(port)def configure(raw_port: str) -> Result[int, str]:
__typhon_q_0__ = parse_port(raw_port)
if isinstance(__typhon_q_0__, __typhon_Err__):
return __typhon_q_0__
port: int = __typhon_q_0__.value
return Ok(port)? propagates a failure inside a function returning Result. The build includes the generated helper imports. View the complete configuration example.
What tyc refuses to compile
Checks for nullability, exhaustiveness and explicit type contracts. Browse the diagnostic catalogue for explanations, examples and fixes, or use tyc explain for offline help.
nullable_useA value that might be None is used where it can't be.
greet(find_user(2))non_exhaustive_matchA match over a sealed union skips one of its variants.
case Circle(r): … # no Squareimmutable_assignSomething declared with let is assigned again.
let n: int = 1 n = 2missing_awaitSynchronous code calls an async function and drops the coroutine.
let u = fetch_user(1)result_error_mismatchA ? passes on an error type the function never declared.
parse(raw)?missing_annotationA parameter or return type has no annotation.
def add(a, b):
The eight rules
The conventions that make types, mutation and failure explicit.
- Every parameter and return type is annotated.There is no inference fallback and no implicit Any.
- Local names are declared with let or mut.let cannot be reassigned. Use mut when you mean to.
- A plain type cannot hold None.Write str? when it can, and narrow it before use.
- Methods live in impl blocks.Classes hold data, and their constructors are generated.
- Any only comes in through unsafe: or .dty stubs.An as! cast checks the shape at runtime instead.
- A match over a sealed union is exhaustive.Add a variant and every match that misses it fails.
- Represent expected errors with Result[T, E].Propagate them with ?, and turn exceptions into values at the edges.
- A let declared without a value is assigned before use.Reading it on a path that never assigned it is an error.
Learn the rest
Try the complete examples, or follow the language tour. If you have typed Python already, tyc migrate gives you a starting point; review and check its output as you adopt the language.
Learn it by writing it.
Follow the language tour, one working example at a time.