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

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.1
File Size Uploaded Provenance
cexec-1.1.1.tar.gz 31.3 MB Without provenance Details

Built distribution (wheel)

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

Total release size: 63.7 MB

Release files / cexec-1.1.1.tar.gz

Download URL cexec-1.1.1.tar.gz
Size 31.3 MB
Tags Source
SHA-256 checksum
How to use checksums
825edf6696a3fe5576a60cfe56f7987d10dec57355b8f36876fc6a1d6e75ef59
BLAKE2b-256 checksum
How to use checksums
87ff321a8d63ad3ff2ec09c83332c55324afcae5da1c56e44384ffb42115039e
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.1-py3-none-any.whl

Download URL cexec-1.1.1-py3-none-any.whl
Size 32.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
e731b602dc071791097ed5e6b1f191c0ed4ab56ebe7c51bf19fccc945e5f269a
BLAKE2b-256 checksum
How to use checksums
c44a89e7709103680899e421994b5c221456148492db0514be7740d4a7b468ee
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.1

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