6 releases

0.5.5 Sep 16, 2022
0.5.4 Dec 4, 2021
0.5.3 Aug 31, 2021
0.5.2 Jul 4, 2021
0.5.0 Jun 3, 2020

#520 in Development tools

31 downloads per month



Execute Python code at compile time to generate Rust code.


use ct_python::ct_python;

static SIN_2: f64 = ct_python! {
    from math import sin

ct_python! {
    print("type num = f64;")

fn main() {
    assert_eq!(num::sin(2.0), SIN_2);

How to use

Use the ct_python!{..} macro to generate Rust code from an embedded Python script. The output of the script (print() and anything else through sys.stdout) is captured, and will be parsed as Rust code.

Python Errors

Any syntax errors or runtime exceptions from the Python code will be reported by the Rust compiler as compiler errors.

Syntax issues

Since the Rust tokenizer will tokenize the Python code, some valid Python code is rejected. See the inline-python documentation for details.


~93K SLoC