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

Uploaded CPython 3.14Windows x86-64

pyqbe-0.0.2-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.2-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.2-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: pyqbe-0.0.2-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.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 bcb8e7c9074d16aa14bdf00fdff848cd3944c4e127f562f5fd2e7c429653ccd0
MD5 0d81124f587b1ed15a77bd8ec06ef340
BLAKE2b-256 47267ba6f033331874741b91c66c9df1387f79f9f0c99f13cf13052393a92104

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyqbe-0.0.2-cp314-cp314-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 91f4b9431ae85e608b944c36887c5b1f9d9c298a9812cb09e5d5e0acbad31cc0
MD5 68a80a94b2ba171f2cfedb7ce05cc0ed
BLAKE2b-256 d1f64ef00604cd5bc6abccccc0480965b6f109da96d2d17dc83aac70b5763600

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyqbe-0.0.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0413a479ae08140870bdec9ba636c08146484539f7695d47898cb09239f88568
MD5 4cab5922ca96d0cf7153a4ac768098e9
BLAKE2b-256 f19b3e2b42a83559e3fd6e2e35321d68454b7da4ec4fcc377730b740a474e412

See more details on using hashes here.

Provenance

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