Skip to main content

The HEIR compiler

Project description

HEIR: Homomorphic Encryption Intermediate Representation

GitHub Workflow Status (with event) GitHub Contributors GitHub Discussions GitHub License OpenSSF Scorecard

An MLIR-based toolchain for homomorphic encryption compilers. Read the docs at the HEIR website.

For more information on MLIR, see the MLIR homepage.

Quickstart (Python)

Pip install the heir_py package

pip install heir_py

Then run an example:

from heir import compile
from heir.mlir import I64, Secret

@compile()  # defaults to scheme="bgv", OpenFHE backend, and debug=False
def func(x: Secret[I64], y: Secret[I64]):
    sum = x + y
    diff = x - y
    mul = x * y
    expression = sum * diff + mul
    deadcode = expression * mul
    return expression

func.setup()
enc_x = func.encrypt_x(7)
enc_y = func.encrypt_y(8)
result_enc = func.eval(enc_x, enc_y)
result = func.decrypt_result(result_enc)

print(
  f"Expected result for `func`: {func.original(7,8)}, FHE result:"
  f" {result}"
)

This will compile the function above using the BGV scheme to machine code via the OpenFHE backend. Then calling the function will encrypt the inputs, run the function, and return the decrypted result. The function call foo(7, 8) runs the entire encrypt-run-decrypt flow for ease of testing.

Building from source

HEIR requires a recent C compiler (see clang_matrix for version-specific support, recent GCCs also tend to work), and some backends like OpenFHE require libomp-dev.

HEIR depends on LLVM (from source) so a clean build may take 15-30 minutes depending on your machine.

This project uses bazel for its build system. Install bazelisk to manage the bazel version automatically. Then, with bazel on your path (pointing to bazelisk), run the following to build the main pass-running tool.

bazel build //tools:heir-opt

Or run an end-to-end test like

bazel test //tests/Examples/openfhe/ckks/halevi_shoup_matvec:all

See the bazel tips page for more example commands and tips on using bazel.

Supported backends and schemes

Backend Library BGV BFV CKKS CGGI
OpenFHE
Lattigo
tfhe-rs
Jaxite

Note some backends do not support all schemes.

Contributing

There are many ways to contribute to HEIR:

Citations

The HEIR project can be cited in in academic work through following entry:

@misc{ali2025heir,
      title={HEIR: A Universal Compiler for Homomorphic Encryption},
      author={Asra Ali and Jaeho Choi and Bryant Gipson and Shruthi Gorantala
              and Jeremy Kun and Wouter Legiest and Lawrence Lim and Alexander
              Viand and Meron Zerihun Demissie and Hongren Zheng},
      year={2025},
      eprint={2508.11095},
      archivePrefix={arXiv},
      primaryClass={cs.CR},
      url={https://arxiv.org/abs/2508.11095},
}

Support disclaimer

This is not an officially supported Google product.

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

heir_py-2026.5.1.tar.gz (14.1 MB view details)

Uploaded Source

Built Distributions

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

heir_py-2026.5.1-cp311-abi3-manylinux_2_28_x86_64.whl (36.6 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ x86-64

heir_py-2026.5.1-cp311-abi3-manylinux_2_28_aarch64.whl (35.2 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.28+ ARM64

heir_py-2026.5.1-cp311-abi3-macosx_11_0_arm64.whl (39.5 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

File details

Details for the file heir_py-2026.5.1.tar.gz.

File metadata

  • Download URL: heir_py-2026.5.1.tar.gz
  • Upload date:
  • Size: 14.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for heir_py-2026.5.1.tar.gz
Algorithm Hash digest
SHA256 0bdfda5526f8d363fc336a01f24ff5f35566e12ba8a96b2fd6dd60cf9702f48e
MD5 ba2cb014e586789e19d91e17c4e1c066
BLAKE2b-256 f214d9a831d73119cfd4fc75bf566bbdade6ef11da8c03d55be0ce94cd5cc222

See more details on using hashes here.

Provenance

The following attestation bundles were made for heir_py-2026.5.1.tar.gz:

Publisher: wheels.yml on google/heir

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

File details

Details for the file heir_py-2026.5.1-cp311-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for heir_py-2026.5.1-cp311-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0bd64ff9d7aa1575c0bd1e5f8170a82f0a944919e566a646928c63f90e97de39
MD5 a2595cf42ff639d16503909542098816
BLAKE2b-256 570a4ab848f7898ce62de56a508ab67a0961a12b9fe3d01e2f4142acd74a11ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for heir_py-2026.5.1-cp311-abi3-manylinux_2_28_x86_64.whl:

Publisher: wheels.yml on google/heir

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

File details

Details for the file heir_py-2026.5.1-cp311-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for heir_py-2026.5.1-cp311-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 023179845841e2383cb84e10c2e6636c132e48d82a42686640f5a46058d5481e
MD5 f60d8e580f2e2bfe23df3b309e145b20
BLAKE2b-256 f3f96715701b65ab0a5de77bd003c1e58f4058bfad30250d5641adeac2c46f62

See more details on using hashes here.

Provenance

The following attestation bundles were made for heir_py-2026.5.1-cp311-abi3-manylinux_2_28_aarch64.whl:

Publisher: wheels.yml on google/heir

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

File details

Details for the file heir_py-2026.5.1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for heir_py-2026.5.1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e35461978995c7d0d6a8ae87bc580af6d4f1c24939e42b086583c6a1753d97e7
MD5 e869959f6b896a59bb0636513da438d1
BLAKE2b-256 d23708edae57f00d203b9624f01795ab588c5db9982dac045123a6efbd7b48d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for heir_py-2026.5.1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: wheels.yml on google/heir

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