Skip to main content

PyTurbo V3

Python 3.10 → 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 © Suleiman 2026


Quick start

python pyturbo.py 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:

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

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

DCE for pythonXY.dll (Windows)

With --min-dll:

  • detects the running Python version (310, 311, 312, 313, ...)
  • finds pythonXY.dll
  • produces a minimal pythonXY-dce.dll
  • generates pythonXY-dce.lib
  • adds #pragma comment(lib, "pythonXY-dce.lib") to the .c

Then:

cl hello.c                # MSVC auto-links the DCE library

Commands

pyturbo transpile <file.py> [-o out.c] [-v]
                    [--min-dll] [--cpython-src PATH]
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

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) ~50× ~50× ~1.3×

Comparison

PyTurbo vs Cython

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

PyTurbo vs Nuitka

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

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.

Platform support

  • Linux ✅
  • macOS ✅
  • Android (Termux, Pydroid3) ✅
  • Windows ✅ (with --min-dll for DLL DCE)

License

Apache License 2.0. See LICENSE.

Metadata

Release files for pyturbo-v3 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyturbo-v3 3.0.0
File Size Uploaded
pyturbo_v3-3.0.0.tar.gz 34.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyturbo-v3 3.0.0
File Interpreter ABI Platform
pyturbo_v3-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 42.4 kB

Release files / pyturbo_v3-3.0.0.tar.gz

Download URL pyturbo_v3-3.0.0.tar.gz
Size 34.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e11a2f4553fc03199f0ccdabc29accb84053a7a625e5771550f650040cc49e1a
BLAKE2b-256 checksum
How to use checksums
455609d80c309ca26c4ab2664df81345425bbb7c47d04b9c9a81feb982676718
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / pyturbo_v3-3.0.0-py3-none-any.whl

Download URL pyturbo_v3-3.0.0-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
864f07862c0037d94f4cf6eacb91361efdd2bb5519ed08de097760a97f9adf75
BLAKE2b-256 checksum
How to use checksums
0d01d8a6abd2223b2dca55c056cc6e347e628e090613dcc12429d20286ceb823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release history Release notifications | RSS feed

3.1.1

2 release files

3.1.0

2 release files

3.0.9

2 release files

3.0.8

2 release files

3.0.7

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

This release

3.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page