Need help with TenSEAL?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

174 Stars 28 Forks Apache License 2.0 198 Commits 18 Opened issues


A library for doing homomorphic encryption operations on tensors

Services available


Need anything else?

Contributors list


Tests Linux Package MacOS Package Windows Package Docker Image

TenSEAL is a library for doing homomorphic encryption operations on tensors, built on top of Microsoft SEAL. It provides ease of use through a Python API, while preserving efficiency by implementing most of its operations using C++.


  • :key: Encryption/Decryption of vectors of integers using BFV
  • :old_key: Encryption/Decryption of vectors of real numbers using CKKS
  • :fire: Element-wise addition, substraction and multiplication of encrypted-encrypted vectors and encrypted-plain vectors
  • :cyclone: Dot product and vector-matrix multiplication
  • :zap: Complete SEAL API under


We show the basic operations over encrypted data, more advanced usage for machine learning applications can be found on our tutorial section

import tenseal as ts

Setup TenSEAL context

context = ts.context( ts.SCHEME_TYPE.CKKS, poly_modulus_degree=8192, coeff_mod_bit_sizes=[60, 40, 40, 60] ) context.generate_galois_keys() context.global_scale = 2**40

v1 = [0, 1, 2, 3, 4] v2 = [4, 3, 2, 1, 0]

encrypted vectors

enc_v1 = ts.ckks_vector(context, v1) enc_v2 = ts.ckks_vector(context, v2)

result = enc_v1 + enc_v2 result.decrypt() # ~ [4, 4, 4, 4, 4]

result = result.decrypt() # ~ [10]

matrix = [ [73, 0.5, 8], [81, -5, 66], [-100, -78, -2], [0, 9, 17], [69, 11 , 10], ] result = enc_v1.matmul(matrix) result.decrypt() # ~ [157, -90, 153]


Using pip

$ pip install tenseal

This installs the last packaged version on pypi. If your platform doesn't have a ready package, please open an issue to let us know.

Build from Source

Supported platforms and their requirements are listed below: (this are only required for building TenSEAL from source) - Linux: A modern version of GNU G++ (>= 6.0) or Clang++ (>= 5.0). - MacOS: Xcode toolchain (>= 9.3) - Windows: Microsoft Visual Studio (>= 10.0.40219.1, Visual Studio 2010 SP1 or later).

If you want to install tenseal from the repository, you should first make sure to have the requirements for your platform (listed above) and CMake (3.12 or higher) installed, then get the third party libraries (if you didn't already) by running the following command from the root directory of the project

$ git submodule init
$ git submodule update

TenSEAL uses Protocol Buffers for serialization, and you will need the protocol buffer compiler too.

If you are on Windows, you will first need to build SEAL library using Visual Studio, you should use the solution file

to build the project
. For more details check the instructions in Building Microsoft SEAL

You can then trigger the build and the installation

$ pip install .

Use Docker

You can use our Docker image for a ready to use environment with TenSEAL installed

$ docker container run --interactive --tty openmined/tenseal


points to the image from the last release, use
for the image built from the master branch.

You can also build your custom image, this might be handy for developers working on the project

$ docker build -t tenseal -f docker-images/Dockerfile-py38 .

To interactively run this docker image as a container after it has been built you can run

$ docker container run -it tenseal

Using Bazel

To use this library in another Bazel project, add the following in your WORKSPACE file:

```load("@bazeltools//tools/builddefs/repo:git.bzl", "git_repository")

gitrepository( name = "orgopenminedtenseal", remote = "", branch = "master", initsubmodules = True, )

load("@orgopenminedtenseal//tenseal:preload.bzl", "tenseal_preload")


load("@orgopenminedtenseal//tenseal:deps.bzl", "tenseal_deps")

tenseal_deps() ```


You can benchmark the implementation at any point by running

$ bazel run -c opt --spawn_strategy=standalone //tests/cpp/benchmarks:benchmark


For support in using this library, please join the #lib_tenseal Slack channel. If you’d like to follow along with any code changes to the library, please join the #code_tenseal Slack channel. Click here to join our Slack community!



Apache License 2.0

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.