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
- Documentation: docs.sunscreen.tech
- Repository: github.com/Sunscreen-tech/spf-runner
- Homepage: sunscreen.tech
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:
- Python 3.10+
- Rust toolchain (rustup.rs)
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
- Download URL: sunscreen_fhe-0.1.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 722.2 kB
- Tags: PyPy, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0903def5fab7e1e9fd33939e02efb192dac7565b6e51a6984fb8d54bf4cafcba
|
|
| MD5 |
4921b23e08338cc2400a4b12da86efca
|
|
| BLAKE2b-256 |
8160ddf0946b5954bc90d6d7e25adb0ec3a5b75d2f2982aef9f640fe2ef6742d
|
File details
Details for the file sunscreen_fhe-0.1.2-cp310-abi3-win_amd64.whl.
File metadata
- Download URL: sunscreen_fhe-0.1.2-cp310-abi3-win_amd64.whl
- Upload date:
- Size: 572.6 kB
- Tags: CPython 3.10+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a821b5a38db45d2fbc87da39eb3cf83bfaffb27eaec681742af6d95dfb036033
|
|
| MD5 |
67331ecc2091dc2f1a5e4d89545a29a2
|
|
| BLAKE2b-256 |
e90712ef998d25eeec8eb4d148322782965614f3e8910b6ff2a4cde0eba75321
|
File details
Details for the file sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 724.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b80dd77baa1699cb590b84795565996ff962199bfe58dfc4544d9730256b32c4
|
|
| MD5 |
8d4ef15268908189949b403e4cf60965
|
|
| BLAKE2b-256 |
b6ad8226ef00a647f6abc649aa8c6600d5cfa02fb2f55a69a444595be6118775
|
File details
Details for the file sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: sunscreen_fhe-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 627.8 kB
- Tags: CPython 3.10+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c2d53b396955c3a50dba566fdb38f26b747754992299fb4297e2460ea0035f9
|
|
| MD5 |
f57780de2ac5ffe57e6d73d68c7e28ea
|
|
| BLAKE2b-256 |
66c2eb6133e322888066a1f933cb9e1af3e2a002c28293c3df2b8d4b2d4d0a62
|
File details
Details for the file sunscreen_fhe-0.1.2-cp310-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: sunscreen_fhe-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 550.2 kB
- Tags: CPython 3.10+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfb6a1e5f124cd9a35367ac19726455ada6e41e1ba14a10ddc6606dacb92f2d2
|
|
| MD5 |
70e831d71575eeab7322c28e56aeb08c
|
|
| BLAKE2b-256 |
1a5a73aeb6589faad2c7948abb10b8f18d9d5f983359b4aafcca393fcf4c3e55
|