Skip to main content

Python client for FHE program runner

Project description

sunscreen-fhe

Python client library for Fully Homomorphic Encryption (FHE) operations using Sunscreen's Parasol technology.

Overview

Sunscreen-fhe provides Python bindings for running FHE programs compiled with the Parasol compiler. FHE allows computations on encrypted data without decryption, enabling privacy-preserving applications.

Features

  • Key generation for FHE operations (secret, public, and compute keys)
  • Encryption and decryption of integers (8, 16, 32, 64-bit, signed and unsigned)
  • Parameter building with method chaining API
  • Support for array operations
  • Mixed plaintext/ciphertext computations
  • Zero runtime dependencies
  • Type-safe Python API with full type stubs

Links

Installation

pip install sunscreen-fhe

Usage

from sunscreen_fhe import KeySet, ParameterBuilder, read_outputs

# Generate keys
keys = KeySet.generate()

# Build parameters: encrypt two 8-bit values, declare one 8-bit output
params = (
    ParameterBuilder()
    .encrypt(100, bit_width=8, signed=False)
    .encrypt(50, bit_width=8, signed=False)
    .output(bit_width=8, size=1)
    .build(keys.public_key)
)

# Save compute key for server
from pathlib import Path
Path("computation.key").write_bytes(keys.compute_key.to_bytes())

# Run the FHE program (params via stdin, output via stdout)
import subprocess
result = subprocess.run(
    ["program_runner", "-e", "program.elf", "-f", "add_u8", "-k", "computation.key"],
    input=params.to_bytes(),
    capture_output=True, check=True
)

# Decrypt outputs
outputs = read_outputs(result.stdout)
decrypted = keys.decrypt(outputs[0], signed=False)

Development

This is a PyO3 extension module built with maturin.

With Nix (recommended)

The Nix development shell provides all required dependencies.

# Enter the Nix development shell (from repository root)
nix develop

# Run all tests (builds everything automatically)
make test-python

# Or run steps individually:
uv sync
maturin develop --release
uv run pytest tests/ -v

Without Nix

Prerequisites:

Note: E2E tests require the FHE test programs which need the Parasol compiler (Nix only). Without Nix, E2E tests will be skipped automatically.

Using uv (recommended):

# Install uv if needed: https://docs.astral.sh/uv/getting-started/installation/

# From sunscreen_fhe directory:
uv sync
uv run maturin develop --release
uv run pytest tests/ -v

Using pip/venv:

# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install maturin and dev dependencies
pip install maturin pytest pytest-cov

# Build and install the extension module
maturin develop --release

# Run tests
pytest tests/ -v

Testing Notes

PyO3 extension modules cannot be tested with cargo test directly because they are shared libraries designed to be loaded by Python. The linker cannot resolve Python symbols when building a standalone test binary. Always test via the maturin develop + pytest path shown above.

License

MIT

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.

sunscreen_fhe-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (801.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

sunscreen_fhe-0.1.1-cp310-abi3-win_amd64.whl (652.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

sunscreen_fhe-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

sunscreen_fhe-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (664.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

sunscreen_fhe-0.1.1-cp310-abi3-macosx_11_0_arm64.whl (622.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

Details for the file sunscreen_fhe-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6ba6a00f43d7fce3197e63c556d561ef373467eaaf7234a9aab0076a91bba576
MD5 54fbfee6b5366ee62f464fa05d8273c1
BLAKE2b-256 256cebc39a591f95bfe4a1363b5b31a16dae380063555bcf7046bea3aadaf523

See more details on using hashes here.

File details

Details for the file sunscreen_fhe-0.1.1-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 2dd718c420479414cb6cd5ee7b9c7a02f07ba015211ced0243b280fe6fdf3203
MD5 0d5b66037c6d85a50c709dd66fbf1aa5
BLAKE2b-256 37a42cb0b5922afa3ed3785e6ab9d916f4ac707b3422a21d244e2307b9c73f9d

See more details on using hashes here.

File details

Details for the file sunscreen_fhe-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4cbd42f0fe431fc48fc300a93f5f49531fb6afbd2591f0ecaa6a7f5771fa9974
MD5 18ddbcfd64d15d15b1614628f5ae4812
BLAKE2b-256 2b83e572d9f2b5d29185229f1b1e9196ee5a7beddbfd2685d9c4b956f4792695

See more details on using hashes here.

File details

Details for the file sunscreen_fhe-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f8a060ec1a60035233560723a54c60253b49c74dc01c51ef598380ae047844f5
MD5 9171733d73b51c577853e5fd38f25be6
BLAKE2b-256 66c7c54e4e1f53a10b3e19f9830895afafc6f6ab1ad7cef74475ea5035665c6a

See more details on using hashes here.

File details

Details for the file sunscreen_fhe-0.1.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0289b97c57902ef997ac59848e79d314eb5479ff168d333c8ea62c6291928b72
MD5 5cd6a6c6e679393a32434cd936eea3da
BLAKE2b-256 96ecb9eef7856727c58be241e49da7d0ca0f4db164831c4945f846a47f3a5959

See more details on using hashes here.

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