Skip to main content

cexec — The C Executor in Python

cexec is a Python library that allows you to compile and run C code on the fly directly from Python. It supports both standard C compilation (via GCC) and hybrid compilation with NASM for heavy loops, packing them into DLLs for maximum performance.

✨ Features

  • Zero Dependencies: Uses only the Python standard library.
  • On-the-fly Execution: Compile and run C code in a single function call.
  • GCC & NASM Hybrid: Uses GCC (C11/C17) for standard code and NASM for heavy loops (Hard-Outlining).
  • Self-Extracting EXE: Can build standalone .exe files with embedded DLLs loaded via LoadLibraryA.
  • Windows x64 Support: Optimized for 64-bit Windows systems.

🚀 Quick Start

Make sure you have Python 3.8+ installed on Windows x64 (this package currently supports only Windows x64).

import cexec

c_code = """
#include <stdio.h>

int main() {
    printf("Hello from C Executor!\\n");
    return 0;
}
"""

output = cexec.execute(c_code)
print(output)

⚙️ Advanced Usage

  1. Hybrid JIT (GCC + NASM)

cexec can automatically find heavy loops and transpile them to NASM, compiling them into a DLL that is loaded dynamically.

import cexec

code = """
#include <stdio.h>

int main() {
    int sum = 0;
    for (int i = 0; i < 1000; i++) {
        sum += i;
    }
    printf("Sum: %d\\n", sum);
    return 0;
}
"""

# use_nasm=True by default
print(cexec.c.execute(code, use_nasm=True))
  1. Pure NASM Execution

You can also write and execute raw NASM assembly directly:

import cexec

nasm_code = """
global main
extern printf
section .data
    fmt db "Hello from NASM!", 10, 0
section .text
main:
    push rbp
    mov rbp, rsp
    sub rsp, 32
    lea rcx, [rel fmt]
    call printf
    xor eax, eax
    leave
    ret
"""

print(cexec.nasm.execute(nasm_code))

⚠️ Important Notes

· Windows Only: This package uses gcc.exe and nasm.exe, which are Windows x64 binaries. It will not work on Linux, macOS, or Android. · Size: The package is ~32 MB (compressed) because it includes a full GCC compiler and NASM assembler.

📦 Installation

pip install cexec

📄 License

This project is distributed under the MIT License. See the LICENSE file for details.

Metadata

Release files for cexec 1.1.2

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

Source distribution (sdist)

Source distribution for cexec 1.1.2
File Size Uploaded Provenance
cexec-1.1.2.tar.gz 31.3 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 63.7 MB

Release files / cexec-1.1.2.tar.gz

Download URL cexec-1.1.2.tar.gz
Size 31.3 MB
Tags Source
SHA-256 checksum
How to use checksums
07690a8b2516bb8ffc29f2fc000cc2ecf375dea388d13145f5cc87c835c27f78
BLAKE2b-256 checksum
How to use checksums
d10649bf3008ccaa5a2d92b5592221e465240f8e89e4f0cf4bde08522408ce06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Release files / cexec-1.1.2-py3-none-any.whl

Download URL cexec-1.1.2-py3-none-any.whl
Size 32.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
5062776a13b5627f81d33de5cbe75b83f362b9b68df2670886ad753a05299ab9
BLAKE2b-256 checksum
How to use checksums
fea8c66387e05e336a6fad243dea442357e3d62d0a7c6b19342b71ca4ecf2d20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.13

Security for cexec 1.1.2

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.

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