Skip to main content

cpile ⚡

✱cpile✱ python code to C code with type annotation, produces readable C code with native C performance


Installation

pip install cpile

Support Features (0.2.0)

  1. Type Mapping : map compatible python type with c type
Python type C type
int (integer) int32_t
str (string) char*
float (floating point) double
bool (boolean) bool <stdbool.h>
None void
  1. Function and Recursion : Full support for typed function signatures and recursive calls (e.g., Fibonacci).
  2. Control Flow : Full support if, else, and elif block with proper c scoping and indentation.
  3. Loop : Support while loop with condition, for loop with range(n), range(start, stop) and range(start, stop, step), break, and continue.
  4. Arrays & 2D Arrays : Support 1D and 2D typed arrays (list[int], list[list[int]]).
  5. Structs : Support classes as C typedef struct definitions with field access.
  6. Variable Declaration : Support variable with type declaration and tracking so variable declare once with their c type and reassigned cleanly.
  7. Arithmetic Operators and Logic : Full Support Binary Operator(+, -, *, /, %), math functions, comparison (>, <, <=, >=, !=, ==), and logic (&&, ||, !).

Project Structure

cpile/
├── src/
│   └── cpile/
│       ├── __init__.py      # Package export (transpile, transpile_file, compile_c)
│       ├── types.py         # Python-to-C type mapping and format specifiers
│       ├── analyzer.py      # AST visitor for type analysis and symbol table
│       ├── codegen.py       # C code generator
│       └── transpiler.py    # Public API & GCC compilation integration
├── test/
│   ├── examples/            # Sample Python programs to transpile
│   │   ├── fibonacci.py
│   │   ├── loops.py
│   │   ├── math_ops.py
│   │   └── conditions.py
│   ├── test_all_examples.py # End-to-end verification suite
│   ├── test_type.py         # Unit tests for types
│   ├── test_analyze.py      # Unit tests for analyzer
│   └── test_codegen.py      # Unit tests for code generator
├── pyproject.toml           # Package configuration
└── README.md

Quickstart

1. Transpile a Python string

import cpile

code = """
def fibonacci(n: int) -> int:
    if n <= 1:
        return n
    return fibonacci(n - 1) + fibonacci(n - 2)
"""

c_code = cpile.transpile(code)
print(c_code)

Output:

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>

int32_t fibonacci (int32_t n) {
  if (n <= 1) {
    return n;
  }
  return fibonacci(n - 1) + fibonacci(n - 2);
}

2. Transpile a Python file

import cpile

c_code = cpile.transpile_file("test/examples/loops.py")

Command Line Interface (CLI)

cpile provides a command line interface to transpile and build programs directly from your terminal.

1. Transpile Python to C

# Print generated C code directly to stdout:
cpile transpile script.py

# Save generated C code to a file:
cpile transpile script.py -o output.c

2. Build Native Binary (Transpile + GCC Compile)

# Transpile and compile directly to an executable binary:
cpile build script.py -o my_program

# Run the compiled binary:
./my_program

Running Verification Tests

Run the full verification suite to transpile all examples and compile each one with gcc:

python3 test/test_all_examples.py

All examples are transpiled into test/build/ and compiled to native .o binaries using gcc.

Metadata

Release files for cpile 0.2.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 cpile 0.2.0
File Size Uploaded Provenance Actions
cpile-0.2.0.tar.gz 10.2 kB Without provenance Details for cpile-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cpile 0.2.0
File Interpreter ABI Platform Actions
cpile-0.2.0-py3-none-any.whl Python 3 none any Details for cpile-0.2.0-py3-none-any.whl

Total release size: 21.6 kB

Release files / cpile-0.2.0.tar.gz

Download URL cpile-0.2.0.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b2ec24e0591b59e5d491ef5ed24aa20b5d8e2d7a5a76c22aeb50d57ae6327cec
BLAKE2b-256 checksum
How to use checksums
ac0411d90da864f5409cff0f738d86703605cae1af3c08f3ea57c3df2343a661
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.2 CPython/3.14.6 Darwin/27.0.0

Release files / cpile-0.2.0-py3-none-any.whl

Download URL cpile-0.2.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cd54f4ed23f2c6b4c3d0987aa90c38f2ea7508e5739c96212455330417c6a99
BLAKE2b-256 checksum
How to use checksums
a763f64e16d2e3aba1e3a7a2d86b84ea0156cf87bf5c42ad036e965345e1122a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.2 CPython/3.14.6 Darwin/27.0.0

Security for cpile 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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