Metadata-Version: 2.4
Name: pyturbo-v3
Version: 3.0.1
Summary: Python 3.10 to C99 transpiler with CPython API and DCE
Home-page: https://github.com/suleiman/pyturbo
Author: Suleiman
License: Apache-2.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: C
Classifier: Environment :: Console
Classifier: Topic :: Software Development :: Compilers
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: author
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-python
Dynamic: summary

# 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.
