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.0-cp310-abi3-win_amd64.whl (652.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

sunscreen_fhe-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (803.4 kB view details)

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

sunscreen_fhe-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (664.4 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

sunscreen_fhe-0.1.0-cp310-abi3-macosx_11_0_arm64.whl (622.7 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ea8bae62efdd5b88671dcb1c3200a78c60224a6b7abc0f35ea6ee7d6427d397f
MD5 00b822fe727dc418f6e78f6046a6cc6b
BLAKE2b-256 dcc948e7c1f2df11f264c0d122cb42ececdfb08996fd9e3d54238e742a283c01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50df8441c717cb7d7573b17e84cb876266f6751a479dd83cad53473cf66b7da3
MD5 ec8a36b9874542cb54f73f2df85395b0
BLAKE2b-256 fe12ea94a0145861baf17f6a41e23588fb86ddd3f29ba4703b8b389b64f10f02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3d2cd1d18645d19047e0ae7b8311e938513a190dad81c924c0392fc412221678
MD5 d92c86fa6305d274b5fb5f0ad1144f48
BLAKE2b-256 398b224269665dd701b02224602a0fa6c5c710ccc3798dc398100ef8cc6f30a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sunscreen_fhe-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b84b7eb7af71b09c056d76c33996ffe1cd9e7f715fa382c9a766f2094fdfded9
MD5 71aff4ea708b17d449af36eb155dcd6f
BLAKE2b-256 8505213cab39d1803f25a59eac0b9b3ea75bdfcb1e7237e6118fb070654ef990

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