Skip to main content

No project description provided

Project description

pyqbe

Python bindings for QBE, a compiler backend that generates optimized assembly. Pass QBE IR as a string, get assembly back — no external QBE binary needed.

Note: This is a hobby project.

What is this?

QBE is a small, fast compiler backend (think LLVM but ~10k lines of C). pyqbe wraps it as a Python package so you can generate assembly programmatically without shelling out to a binary.

import pyqbe

ir = """
function w $add(w %a, w %b) {
@start
    %c =w add %a, %b
    ret %c
}
"""

asm = pyqbe.compile(ir)
print(asm)

Why?

If you're building a compiler, DSL, or code generation tool in Python, you need a backend. QBE gives you optimized assembly for free — pyqbe makes it accessible from Python without any system dependencies.

Targets

QBE supports:

  • amd64 — Linux (SysV ABI) and macOS
  • arm64 — Linux and macOS (Apple Silicon)
  • riscv64 — Linux
  • amd64_win — Windows (64-bit, requires UNIX toolchain)

Installation

pip install pyqbe

From source

Requires a C compiler and g++ with pybind11.

git clone --recurse-submodules https://github.com/Marpuriganesh/pyqbe
cd pyqbe
pip install .

--recurse-submodules is required — QBE is included as a git submodule.

Status

Early development. API is not stable.

  • QBE as git submodule
  • wrapper/qbe_api.c — FILE* shim + C entry point
  • wrapper/binding.cpp — pybind11 glue
  • meson.build — build config
  • GitHub Actions + cibuildwheel for prebuilt wheels
  • Windows scenario (deferred)

How it works

QBE's parse() function takes a FILE*. pyqbe wraps this with a thin shim that turns a Python string into an in-memory FILE* (fmemopen on Linux/macOS, tmpfile fallback on Windows), calls QBE's internals directly, and captures the assembly output — all in-process.

Python string (QBE IR)
        ↓
   string_to_file()        ← FILE* shim
        ↓
   qbe parse() + emit()    ← QBE internals
        ↓
   assembly string

Related

  • QBE — the compiler backend this wraps
  • LowPy — systems programming language using pyqbe as its backend

License

QBE is MIT licensed. pyqbe wrapper code is also MIT licensed.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

pyqbe-0.0.3-cp314-cp314-win_amd64.whl (344.3 kB view details)

Uploaded CPython 3.14Windows x86-64

pyqbe-0.0.3-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (203.7 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

pyqbe-0.0.3-cp314-cp314-macosx_11_0_arm64.whl (162.7 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

File details

Details for the file pyqbe-0.0.3-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pyqbe-0.0.3-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 344.3 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyqbe-0.0.3-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 51b4e28cf86c1ad91ace2e82c483151dc8f3e2081bda93ed826f2e6bbce08bc3
MD5 690b89cffaeea59431622b6c0483a2c3
BLAKE2b-256 91dad08e9c0664add0324e18948c3acf7fb611dc2a43470bfd594b03ff7fc22e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqbe-0.0.3-cp314-cp314-win_amd64.whl:

Publisher: wheels.yml on Marpuriganesh/pyqbe

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

File details

Details for the file pyqbe-0.0.3-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqbe-0.0.3-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 13933b00c51a9c264c827b262778a64e721d4cdb1fb260b9458f520471e57007
MD5 47e19a83ed419cc2ed32363af926ad3c
BLAKE2b-256 f608cefe52ddfdbb6eabcf4ac43a50afea6f9119de2442fc234c2690d8df05cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqbe-0.0.3-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on Marpuriganesh/pyqbe

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

File details

Details for the file pyqbe-0.0.3-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqbe-0.0.3-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ecbc81c6765969d8acf42e8f6fe737234877e74ada4cf2cc805f9ba38ba80a29
MD5 8760078825767a0d592cdfec56ae0f03
BLAKE2b-256 094d6896b8fb28bed4fd529b44d5f5d8f86c1dd51e3915f87dc3aafa40f10781

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqbe-0.0.3-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: wheels.yml on Marpuriganesh/pyqbe

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