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

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.3
File Size Uploaded Provenance
cexec-1.1.3.tar.gz 32.2 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 65.5 MB

Release files / cexec-1.1.3.tar.gz

Download URL cexec-1.1.3.tar.gz
Size 32.2 MB
Tags Source
SHA-256 checksum
How to use checksums
a4692ef79a8521047b0acd316038a7d7c32af6f49731abb8556b77c3db2dfbb4
BLAKE2b-256 checksum
How to use checksums
9f70bd06c259f53c2bb44d28a8cb5a4275ca5ee4a006f53b0fc4bfd9f773a859
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.3-py3-none-any.whl

Download URL cexec-1.1.3-py3-none-any.whl
Size 33.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2a076374cc5669a7a673b21c7a055d88b8953067a414d7f2c7f9f0c30e551c16
BLAKE2b-256 checksum
How to use checksums
c90be13e53173fc8f612c19f8f3adb893d7037a7d970bd3be0eee30bf5a1793d
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.3

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