Skip to main content

cpile ⚡

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


Support Features (0.1.0)

  1. Type Mapping : map compatible python type with c type
Python type C type
int (interger) 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)
  4. Variable Declaration : Support variable with type declaration and tracking so variable declare once with their c type and reassigned cleanly
  5. Arithmetic Operators and Logic : Full Support Binary Operator(+, -, *, \, %) comparison (>, <, <=, >=, !=, ==) 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")

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.1.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.1.0
File Size Uploaded Provenance Actions
cpile-0.1.0.tar.gz 9.6 kB Without provenance Details for cpile-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 20.7 kB

Release files / cpile-0.1.0.tar.gz

Download URL cpile-0.1.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a6afe0711c964b211f43c2b78aa058490ed1c714f5e2cfaca2a5ea49454fb567
BLAKE2b-256 checksum
How to use checksums
dc36da342e7e774fd8ead3b06d92254eeff4f88c1abd6e1a66d3855fa1b290e9
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.1.0-py3-none-any.whl

Download URL cpile-0.1.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f4a0178b55004f88a6468f0cded332de29bc86ad18d0b05e4bce3a83a8a4ee1b
BLAKE2b-256 checksum
How to use checksums
1d569a66c632f6a1b8ccb1fd99cf128571b2f80cf2bc904a3eb7d445328303a8
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.1.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