Skip to main content

PolyHE

Simple and Pythonic Homomorphic Encryption

Designed to make homomorphic encryption approachable, predictable and easy to integrate into Python applications.

  • Native Python operators (+, -, *)
  • Transparent operations with Python and NumPy objects
  • Built-in pickle support for encrypted objects
  • Predictable type, dtype and shape preservation
  • Arbitrary typed, shaped and sized arrays
  • No plaintext encoders or packing APIs required
  • Automatic multi-ciphertext management beyond backend slot limits
  • Portable ciphertexts with embedded public context
  • Unified high-level interface across multiple FHE backends
  • Transparent serialization and remote computation workflows
  • Familiar Python semantics with minimal cryptographic boilerplate
  • Designed for experimentation, prototyping and educational use

Example

import polyhe
ctx = polyhe.new()

# Numbers
p1 = 1
p2 = -1
c1 = ctx.encrypt(p1)
c2 = ctx.encrypt(p2)
c3 = (c1 * c2) + p1
p3 = ctx.decrypt(c3)
# 0

# Lists
p1 = [0.3, 0.4]
p2 = [0.4, 0.3]
c1 = ctx.encrypt(p1)
c2 = ctx.encrypt(p2)
c3 = -c1 + c2
p3 = ctx.decrypt(c3)
# [0.1, -0.1]

# NumPy
import numpy as np
p1 = np.full((2, 3, 4), 0.4, np.float64)
p2 = np.full((2, 3, 4), 0.3, np.float64)
c1 = ctx.encrypt(p1)
c2 = ctx.encrypt(p2)
c3 = (c1 - c2) * 2
p3 = ctx.decrypt(c3)
# np.full((2, 3, 4), 0.2, np.float64)

Install

Production

pip install polyhe[openfhe,tenseal]

Development

git clone https://github.com/hpca-uji/polyhe.git
cd polyhe
pip install -e .

Documentation

Constants

  • Backend:

    Encryption backend

    • OPENFHE (installed with polyhe[openfhe], source)
    • TENSEAL (installed with polyhe[tenseal], source)
    • UARCHFHE

Structures

  • Options(...)

    Encryption options

    • slots: int = 13

      2 ** slots elements per backend ciphertext

    • scale: int = 40

      2 ** scale typical operational scale

    • security: int = 128

      Security level

      Typical values: 128, 192 and 256.

Functions

  • new(backend, options)

    Create a communicator.

    • backend: Backend = Backend.OPENFHE
    • options: Options = Options()

Classes

  • core.Context(options)

    Encryption context implementation

    • options: Options = Options()

    • encrypt(data) -> Ciphertext

      Encrypt data to ciphertext

    • decrypt(obj: Ciphertext)

      Decrypt cypertext to data

  • core.Ciphertext(...)

    Ciphertext has -, + and * operator support, with either another ciphertext or plain data.

    Note: Support for operation may vary between backends

  • {backend}.Context(options)

    Concrete encryption context implementation for the given backend

Notes

PolyHE prioritizes simplicity and ease of use over advanced features. It is designed for prototyping and experimentation purposes rather than production-grade deployments. If you require fine-grained control over encryption parameters, performance tuning, or advanced schemes, we recommend using the underlying backend libraries directly. Alternatively, Pyfhel (source) is a mature Python library that provides more comprehensive access to homomorphic encryption features.

Acknowledgments

The library has been partially supported by:

  • Project PID2023-146569NB-C22 "Inteligencia sostenible en el Borde-UJI" funded by the Spanish Ministry of Science, Innovation and Universities.
  • Project C121/23 Convenio "CIBERseguridad post-Cuántica para el Aprendizaje FEderado en procesadores de bajo consumo y aceleradores (CIBER-CAFE)" funded by the Spanish National Cybersecurity Institute (INCIBE).

Metadata

Release files for polyhe 1.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polyhe 1.0.5
File Size Uploaded Provenance Actions
polyhe-1.0.5.tar.gz 22.9 kB Without provenance Details for polyhe-1.0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polyhe 1.0.5
File Interpreter ABI Platform Actions
polyhe-1.0.5-py3-none-any.whl Python 3 none any Details for polyhe-1.0.5-py3-none-any.whl

Total release size: 47.0 kB

Release files / polyhe-1.0.5.tar.gz

Download URL polyhe-1.0.5.tar.gz
Size 22.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70cc9d772caa9b55f319d84ca7fe2fed539b8b0026f2251051715b2170eb0492
BLAKE2b-256 checksum
How to use checksums
2f35e8273d9eb42d67811e4aed07bac58e312f883faece9869a7798bd52f72b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / polyhe-1.0.5-py3-none-any.whl

Download URL polyhe-1.0.5-py3-none-any.whl
Size 24.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60b8926d5b4b6ffd7be34687f1f6af7f92b260a23c924f17b9a48fac0e456e22
BLAKE2b-256 checksum
How to use checksums
baae574829f71df7f92f5674cab50d9ad60173e8ae25b1f597a81a74f5c87897
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for polyhe 1.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page