This document lists all Python features currently supported by Tsuchinoko transpiler.
x: int = 10)int, float, str, bool, Nonelist[T], dict[K, V], tuple[...]Optional[T], T | Nonex or default → unwrap_or, ternary with None check (V1.5.0)+, -, *, /, //, %, **, @ (V1.3.0)==, !=, <, >, <=, >=0 < x < 10 → 0 < x && x < 10) (V1.6.0)and, or, notin, not in (V1.3.0)is, is not (with None comparison)&, |, ^, ~, <<, >> (V1.3.0)+=, -=, *=, /=, //=, %=, **=, &=, |=, ^=, <<=, >>= (V1.3.0)range(), collection iterationx if cond else y)lambda x: x + 1)func(name="value"))def func(x=10)) (V1.2.0)def func(**kwargs) → HashMap<String, Value>) (V1.6.0){k: v for k, v in items}) (V1.3.0){1, 2, 3} → HashSet) (V1.5.0){x*2 for x in nums} → HashSet) (V1.6.0)nums[-1])[:3], [-3:], [1:n-1])[::2], [::-1]) (V1.5.0)a[i], a[j] = a[j], a[i] → a.swap())l.copy() → l.to_vec()) (V1.2.0)a, b, c = 1, 2, 3) (V1.3.0)pop, insert, remove, extend, clear (V1.5.0)keys, values, get, pop, update (V1.5.0)add, remove, discard, union, intersection (V1.5.0)__init__self.attr)@staticmethod)@dataclass) (V1.2.0 Partial)class Child(Parent)) → Composition (V1.6.0)super().method() → self.base.method()) (V1.6.0)with open(...) as f: → { let f = ...; })Tsuchinoko V1.2.0 introduces a Resident Python Worker to support libraries that are difficult to transpile directly to Rust.
import numpy as np)import pandas as pd)import cv2) (V1.4.0)from Import Syntax (V1.4.0) 🆕from numpy import mean, stdpy_bridge.call_json("numpy.mean", ...) callsTsuchinoko now supports persisting Python objects across bridge calls. This allows for:
df["column"]).len() - get lengthrange() - numeric range iterationprint() - console output (supports f-string debug "{x=}" / "{:?}")list() - convert to listmin(), max() - min/max valuesabs() - absolute valueint(), float(), str(), bool() - type conversionsenumerate() - indexed iteration (V1.3.0)zip() - parallel iteration (V1.3.0)sorted() - sorted list generation (V1.3.0)reversed() - reverse iteration (V1.3.0)sum() - sum calculation (V1.3.0)all(), any() - boolean check (V1.3.0)map(), filter() - functional transformation (V1.3.0)assert - assertion statement (V1.3.0)input() - user input with optional prompt (V1.5.0)round() - rounding with precision (V1.5.0)chr(), ord() - character/code point conversion (V1.5.0)bin(), hex(), oct() - number format conversion (V1.5.0)isinstance() - type checking → DynamicValue enum + match (V1.6.0)math.sqrt, sin, cos, tan, asin, acos, atan, exp, log, log10, log2, abs, floor, ceil, roundmath.pi, math.e, math.tau, math.inf, math.nan → Native Rust constantsf"Hello {name}")
"{x=}" / "{:?}" supported (V1.2.0).upper(), .lower(), .strip(), .split(), .join(), etc..replace(), .startswith(), .endswith(), .find(), .rfind(), .index(), .count().isdigit(), .isalpha(), .isalnum()catch_unwind)except (ValueError, TypeError):) (V1.5.0)except ValueError as e:) (V1.5.0)else runs when no exception) (V1.5.2)Err(TsuchinokoError) or panic!)raise A from B) - exception chaining with cause (V1.5.2)Result<T, TsuchinokoError> (V1.5.2)TsuchinokoError)MyType = list[int])Callable[[T], U])if x is None / if x is not None)[!NOTE] Direct PyO3 calls are still supported but the Resident Worker is recommended for compatibility.