Registry / auth-security / tenseal

tenseal

JSON →
library0.3.16pypypiunverified

TenSEAL (v0.3.16) is a Python library providing homomorphic encryption operations on tensors, built on Microsoft SEAL. It enables computations on encrypted data without decrypting it, enhancing privacy for machine learning and other applications. Releases are frequent, often incorporating updates from the underlying SEAL library and expanding Python version support.

pip install tenseal
INSTALL
IMPORT
SIG · TENSEAL
T
tenseal
auth-securitypythonv0.3.16
Install
1.9s avg
Import
Disk
28MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.16 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.9s · import 0.000s · 31MB
28MB installed
● package 28MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tenseal
import tenseal
import tenseal as ts

This quickstart demonstrates setting up a TenSEAL context for the CKKS scheme, encrypting two vectors, performing homomorphic addition on them, and then decrypting the result. It highlights the critical steps of context initialization, key generation, and scale setting for encrypted computations.

import tenseal as ts # 1. Setup TenSEAL Context for CKKS scheme # These parameters are critical for security and functionality. poly_mod_degree = 8192 coeff_mod_bit_sizes = [60, 40, 40, 60] # Create a TenSEAL context context = ts.context( ts.SCHEME_TYPE.CKKS, poly_mod_degree=poly_mod_degree, coeff_mod_bit_sizes=coeff_mod_bit_sizes ) # Generate keys for homomorphic operations (e.g., rotations, relinearization for multiplication) context.generate_galois_keys() context.generate_relin_keys() # Set the scale for CKKS scheme # The scale defines the precision of computations. scale = 2**40 context.global_scale = scale # 2. Encrypt some data vector1 = [0, 1, 2, 3, 4] vector2 = [5, 6, 7, 8, 9] encrypted_vector1 = ts.ckks_vector(context, vector1) encrypted_vector2 = ts.ckks_vector(context, vector2) # 3. Perform homomorphic operations (e.g., addition) encrypted_sum = encrypted_vector1 + encrypted_vector2 # 4. Decrypt and verify # The decryption operation uses the secret key from the context. decrypted_sum = encrypted_sum.decrypt() print(f"Original vector 1: {vector1}") print(f"Original vector 2: {vector2}") print(f"Encrypted sum (truncated): {decrypted_sum[:5]}") # Print first 5 elements # Expected result: [5.0, 7.0, 9.0, 11.0, 13.0]
Debug
Known issues
breakingSupport for Python 3.7 was dropped in TenSEAL v0.3.15. Projects requiring Python 3.7 must use TenSEAL v0.3.14 or earlier.
fix
Upgrade to Python 3.8 or newer, or pin TenSEAL to version <=0.3.14.
affects: >=0.3.15
gotchaThe choice of homomorphic encryption parameters (e.g., `poly_mod_degree`, `coeff_mod_bit_sizes`, `global_scale`) is crucial for both security and functionality. Incorrect parameters can lead to insecure encryption, operations failing, or insufficient precision.
fix
Carefully consult TenSEAL and SEAL documentation for appropriate parameter selection based on security requirements, desired precision, and the complexity of operations. Start with recommended parameters for common schemes.
affects: All
gotchaPerformance of homomorphic encryption operations is significantly lower than plaintext operations. Large vectors, high polynomial degrees, or complex operations can be very resource-intensive.
fix
Optimize vector sizes, choose the smallest secure parameters, and consider algorithmic changes to reduce the number or complexity of encrypted operations. Use TenSEAL's built-in optimized operations where possible.
affects: All
gotchaUpdates to the underlying Microsoft SEAL library (e.g., in v0.3.9, v0.3.13, v0.3.14) can subtly change behavior, default parameters, or introduce new features. While TenSEAL aims for abstraction, parameter-sensitive operations might be affected.
fix
After upgrading TenSEAL to a new minor version (especially one that updates the underlying SEAL version), review and re-validate your encryption context parameters and test critical operations.
affects: All
Upgrade
Version history
0.3.16latest on PyPI · released Feb 28, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
39 hits · last 30 days
node
34
Amazon
1
OpenAI (training)
1
Resources
tenseal — pip install tenseal · libregistry