Skip to main content

Deterministic bounded Python-to-C source transpiler

Project description

PyCForge

PyPI Python CI License: GPL v3

PyCForge is a deterministic Python-to-C source transpiler with a full PyQt5 desktop workspace, a command-line interface, and a Python API. It converts a documented, deliberately bounded Python subset into readable C11 source while producing diagnostics, source mappings, decision traces, and reproducible fingerprints.

PyCForge 0.15.2 desktop workspace showing a Python source bundle, generated C, and the transpilation summary

Open the 32-page PyCForge Programmer's Conversion Guide (PDF)

Quick start

PyCForge requires Python 3.11 or newer. Install it from PyPI:

python -m pip install pycforge

That one command installs PyQt5 and the desktop application as required dependencies. There is no GUI extra and no separate desktop package.

Launch the desktop workspace:

pycforge-workspace

The equivalent module command is:

python -m pycforge.ide

A 60-second conversion

Save this as example.py:

def add(left: int, right: int) -> int:
    return left + right

Convert it:

pycforge convert example.py --output example.c

PyCForge produces:

#include <stdint.h>

int64_t add(int64_t left, int64_t right);

int64_t add(int64_t left, int64_t right)
{
    return left + right;
}

The generated C is deterministic for the same authenticated source bundle and converter configuration.

What PyCForge provides

  • A Python-first PyQt5 workspace with document tabs, source splitting, navigation, search, outline, command palette, and conversion history.
  • Explicit source bundles containing 1 to 64 Python documents, including bounded cross-module function imports.
  • Read-only generated C with diagnostics, source mappings, conversion summary, decision trace, and telemetry inspectors.
  • Isolated, cancellable desktop conversion so the converter does not run on the GUI thread.
  • A headless CLI for scripts and build pipelines.
  • A Python API for applications that need structured conversion results.
  • Stable diagnostics and fail-closed rejection of unsupported Python.

Command-line interface

Write generated C to a file:

pycforge convert input.py --output generated.c

Emit the structured result as JSON:

pycforge --format json convert input.py

See all commands and options:

pycforge --help

Python API

from pycforge import ConversionRequest, PythonToCConverter

source = """\
def add(left: int, right: int) -> int:
    return left + right
"""

result = PythonToCConverter().convert(
    ConversionRequest.from_source(source)
)

if result.generated_c is not None:
    print(result.generated_c)
else:
    for diagnostic in result.diagnostics:
        print(diagnostic)

The desktop workspace, CLI, and Python API use the same converter and result contracts.

Supported Python

PyCForge is intentionally not a general Python runtime. Its current subset includes strictly annotated top-level functions using selected scalar values, arithmetic and comparisons, if/elif/else, bounded while and range loops, direct eligible function calls, fixed homogeneous containers, and a bounded static-record profile.

Anything outside the documented subset is unsupported by default and is rejected with diagnostics rather than silently approximated. Read the exact supported-Python specification before adopting PyCForge for production input.

Safety boundary

PyCForge parses supplied source as data. It does not import or execute the input Python, scan the host environment for modules, or resolve undeclared files. It stops after C source generation and does not compile, assemble, link, load, or execute the generated C.

Python int values map to the documented signed 64-bit representation domain; other supported Python values likewise follow explicit target-C contracts. Review the product boundary and the Programmer's Conversion Guide for the complete limitations.

Documentation

Development

git clone https://github.com/lastforkbender/pycforge.git
cd pycforge
python -m venv .venv
python -m pip install --upgrade pip
python -m pip install -e .
python -m pip install pytest
QT_QPA_PLATFORM=offscreen python -m pytest -q

The normal editable installation includes PyQt5, matching the package users receive from PyPI. Automated release checks cover Python 3.11 and 3.12 on Linux with real PyQt5 widgets using Qt's offscreen platform.

License

PyCForge is free software released under the GNU General Public License v3.0 only.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycforge-0.15.2.tar.gz (418.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pycforge-0.15.2-py3-none-any.whl (501.9 kB view details)

Uploaded Python 3

File details

Details for the file pycforge-0.15.2.tar.gz.

File metadata

  • Download URL: pycforge-0.15.2.tar.gz
  • Upload date:
  • Size: 418.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pycforge-0.15.2.tar.gz
Algorithm Hash digest
SHA256 86b00dc56eaa39883e0f32becc0ad112f14abc1b0844e5610e3887822593fd9e
MD5 c2b67a9c836403e3bdd0d004fb3330da
BLAKE2b-256 d57f476f42337afc9f118518a0d8ed0ee675e3fa4f95b3bd876c473fde6f77b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycforge-0.15.2.tar.gz:

Publisher: release.yml on lastforkbender/pycforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pycforge-0.15.2-py3-none-any.whl.

File metadata

  • Download URL: pycforge-0.15.2-py3-none-any.whl
  • Upload date:
  • Size: 501.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pycforge-0.15.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4aa8bdb9e1e266f3ee9c0ff85094fd2f7c22fafdb4b65be3ee16fcb99ab12900
MD5 2ebda1cff90ab5fd325603c91d03b759
BLAKE2b-256 f09125d7d1b97857218d4fab1e627fa0df6793cd3bfe534e1865aa6225a56d8b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pycforge-0.15.2-py3-none-any.whl:

Publisher: release.yml on lastforkbender/pycforge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page