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.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (722.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

sunscreen_fhe-0.1.2-cp310-abi3-win_amd64.whl (572.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (724.8 kB view details)

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

sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (627.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

sunscreen_fhe-0.1.2-cp310-abi3-macosx_11_0_arm64.whl (550.2 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0903def5fab7e1e9fd33939e02efb192dac7565b6e51a6984fb8d54bf4cafcba
MD5 4921b23e08338cc2400a4b12da86efca
BLAKE2b-256 8160ddf0946b5954bc90d6d7e25adb0ec3a5b75d2f2982aef9f640fe2ef6742d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a821b5a38db45d2fbc87da39eb3cf83bfaffb27eaec681742af6d95dfb036033
MD5 67331ecc2091dc2f1a5e4d89545a29a2
BLAKE2b-256 e90712ef998d25eeec8eb4d148322782965614f3e8910b6ff2a4cde0eba75321

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b80dd77baa1699cb590b84795565996ff962199bfe58dfc4544d9730256b32c4
MD5 8d4ef15268908189949b403e4cf60965
BLAKE2b-256 b6ad8226ef00a647f6abc649aa8c6600d5cfa02fb2f55a69a444595be6118775

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1c2d53b396955c3a50dba566fdb38f26b747754992299fb4297e2460ea0035f9
MD5 f57780de2ac5ffe57e6d73d68c7e28ea
BLAKE2b-256 66c2eb6133e322888066a1f933cb9e1af3e2a002c28293c3df2b8d4b2d4d0a62

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dfb6a1e5f124cd9a35367ac19726455ada6e41e1ba14a10ddc6606dacb92f2d2
MD5 70e831d71575eeab7322c28e56aeb08c
BLAKE2b-256 1a5a73aeb6589faad2c7948abb10b8f18d9d5f983359b4aafcca393fcf4c3e55

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