PyTurbo V3

Python 3.10 to C99 transpiler with CPython API and DCE.

Optimization method: all you can make to C99; the rest through CPython API.

Author: Suleiman
License: Apache 2.0
Copyright 2026 Suleiman


QUICK START

    pyturbo transpile hello.py -o hello.c -v

Output:

    hello.c              C99 + inline CPython declarations (~5 KB)
    hello.h              function prototypes
    hello.manifest.json  full analysis report

Compile with any C compiler:

    gcc -std=c99 hello.c -lpython3.11 -o hello
    ./hello

Or MinGW, clang, tcc, MSVC. Any of them works.


FEATURES

C99 where possible:

    numbers                                -> double
    arithmetic                             -> native + - * /
    for i in range(n)                      -> for (double i = 0; i < n; i += 1)
    +=, -=, *=, ...                        -> native
    print(x, y)                            -> printf("%g %g\n", x, y)
    numeric function parameters            -> unboxed to double
    numeric return values                  -> boxed via PyFloat_FromDouble

CPython API fallback:

    strings, lists, tuples, dicts
    imports, module calls
    classes (via type())
    exceptions
    lambdas

DCE for Python.h:

    reads Python.h from the system
    extracts only the used prototypes (~15 of ~1800)
    inlines them into the .c file
    no #include <Python.h>
    no -I flag needed
    portable .c

DLL isolation on Windows with --min-dll:

    detects the running Python version (310, 311, 312, 313, ...)
    finds pythonXY.dll
    produces an isolated copy next to the .c file
    no Visual Studio required
    uses a pure-Python PE parser

Then:

    cd pyturbo_dist
    gcc hello.c -L. -lpython311 -o hello.exe

Or with MSVC, clang, tcc. Any of them.


COMMANDS

    pyturbo transpile <file.py> [-o out.c] [-v] [--min-dll]
    pyturbo analyze   <file.py>
    pyturbo infer     <file.py>
    pyturbo tokens    <file.py>
    pyturbo version
    pyturbo help


EXAMPLE

    import math

    def sum_squares(n):
        total = 0
        for i in range(n):
            total += i * i
        return total

    def main():
        r = sum_squares(100)
        print("Result:", r)
        print("Sqrt:", math.sqrt(r))

    main()

Generated C (excerpt):

    PyObject* py_user_sum_squares(PyObject* py_n) {
        double py_n_v = PyFloat_AsDouble(py_n);
        double py_total = (double)((0L));
        for (double py_i = (double)((0));
             py_i < (double)(py_n_v);
             py_i += (double)((1))) {
            py_total += py_i * py_i;
        }
        return PyFloat_FromDouble(py_total);
    }

    PyObject* py_user_main(void) {
        PyObject* py_r = py_user_sum_squares(PyLong_FromLong(100L));
        double py_r_v = PyFloat_AsDouble(py_r);
        printf("Result: %g\n", py_r_v);

        PyObject* _m = PyImport_ImportModule("math");
        PyObject* _f = PyObject_GetAttrString(_m, "sqrt");
        PyObject* _t = PyObject_Vectorcall(_f, &py_r, 1, NULL);
        double _t_v = PyFloat_AsDouble(_t);
        printf("Sqrt: %g\n", _t_v);

        Py_INCREF(Py_None);
        return Py_None;
    }


SIZE COMPARISON

    feature                PyTurbo V3   Cython       Nuitka
    ---------------------  -----------  -----------  -----------
    input                  .py          .pyx         .py
    annotations            not needed   needed       not needed
    output                 .c           .c           .c / .exe
    .c size                ~5 KB        ~500 KB      ~1 MB
    binary                 ~50 KB       ~1 MB        ~5 MB
    dependencies           0 (CPython)  3            5
    Python.h               inlined      #include     #include
    DLL DCE (Windows)      yes          no           no
    works on Android       yes          no           no
    speed (numeric)        ~50x         ~50x         ~1.3x


PYTURBO VS CYTHON

Cython requires .pyx syntax with cdef, cpdef.
PyTurbo accepts pure Python and infers types automatically.

Cython:  knight from the Middle Ages.
PyTurbo: hacker from the future.

Both produce fast C.
Both are peers in the same category.
Different eras, different styles.

Cython:
    full plate armor: .pyx, cdef, cpdef
    broadsword: #include <Python.h> (~1800 prototypes)
    castle: ~3 MB package, 150,000 lines
    500 contributors
    18 years old

PyTurbo:
    t-shirt: pure .py
    scalpel: inline Python.h (~15 prototypes)
    laptop: 34 KB, ~3200 lines
    1 author
    brand new


PYTURBO VS NUITKA

Nuitka compiles for packaging (.exe).
PyTurbo focuses on generating minimal C with DCE.

Nuitka pulls in the full Python runtime.
PyTurbo removes unused declarations and inlines only the needed
~15 prototypes directly into the .c file.


DCE

Cython and Nuitka both require #include <Python.h> and pull
in all ~1800 prototypes.

PyTurbo removes unused declarations and inlines only the needed
~15 prototypes directly into the .c file.

On Windows with --min-dll, PyTurbo also isolates pythonXY.dll
next to the .c file, so the .exe loads our copy first
(Windows side-by-side rule).

No Visual Studio required.
Uses a pure-Python PE parser.


PLATFORM SUPPORT

    Linux                       yes
    macOS                       yes
    Android (Termux, Pydroid3)  yes
    Windows                     yes (with --min-dll for DLL isolation)

On Windows: best.
On Linux/macOS/Android: same .c output, no DLL isolation.

Why Windows is best:
    - #pragma comment (auto-link) — optional
    - dumpbin, editbin, msbuild — optional
    - pyturbo_dist/ with isolated DLL
    - minimal distribution size

Why other platforms still work:
    - the .c is standard C99
    - header DCE works everywhere
    - portable output (no -I flag)
    - any C compiler


WHY PYTURBO

Not a new category.
The best in an existing category.

Category: Python-to-C transpilers.
Peers: Cython, Nuitka.

PyTurbo is the best when you want:
    - pure Python input, no annotations
    - tiny .c (5 KB)
    - no -I flag
    - minimal distribution on Windows
    - Android support
    - zero dependencies

Cython is the best when you want:
    - numpy integration
    - C++ integration
    - maximum speed with annotations
    - production ecosystem

Nuitka is the best when you want:
    - .exe packaging
    - full Python compatibility
    - no annotations needed


LICENSE

Apache License 2.0.
See LICENSE.