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.1-cp314-cp314-win_amd64.whl (343.9 kB view details)

Uploaded CPython 3.14Windows x86-64

pyqbe-0.0.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (203.4 kB view details)

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

pyqbe-0.0.1-cp314-cp314-macosx_11_0_arm64.whl (162.3 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: pyqbe-0.0.1-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 343.9 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.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 d50e1958dd0827b7a42d4a200ed2b4245c3ea5b7b97a29aad627f844755eb5cc
MD5 369db2a633b0e30b6f571a209ca8c5a0
BLAKE2b-256 5b53fd4c2f06a311a24ca2726968e4d30b12b9622dd2a1665080f34a784accda

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqbe-0.0.1-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.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for pyqbe-0.0.1-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8795353cf80cf0619bf6947b3a5904d89fb915736f1dd0e0c8064bb748d7a9b8
MD5 125183eb52992d90d814510c060b5ba2
BLAKE2b-256 ebedda8b6b135997ec9ccb898e39b426a010cb8fb607646622c87698a856dcd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqbe-0.0.1-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.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyqbe-0.0.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e4a9a35283a12f89269a7089ed920d4b45c67de5af5dac32480c0f77d4dd0030
MD5 b72511f2762d5f888610d694d529614f
BLAKE2b-256 2f18d5547b2aa32c250ba3e22dda0ef02af2d9a8bac7bf4c8a2c8c44598d9a06

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyqbe-0.0.1-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