Skip to main content

Simple and Pythonic Homomorphic Encryption

Project description

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
p3 = ctx.decrypt(c3)
# np.full((2, 3, 4), 0.1, np.float64)

Install

Production

pip install polyhe

Development

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

Documentation

Constants

  • Backend:

    Encryption backend

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).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

polyhe-1.0.3.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

polyhe-1.0.3-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file polyhe-1.0.3.tar.gz.

File metadata

  • Download URL: polyhe-1.0.3.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for polyhe-1.0.3.tar.gz
Algorithm Hash digest
SHA256 3c0fa009dc7bddfe4fc1118bdc76afbe24cb7e48f4fb67b6ab095bde5b8c6b56
MD5 929433a9254b84f32a1221d38ea22841
BLAKE2b-256 a512953a0ba96a6df47c2d25d1d8a958d5234984c950916787eafd2726a186ff

See more details on using hashes here.

File details

Details for the file polyhe-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: polyhe-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for polyhe-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a2028a5ed2133e9024ee08b2be68ed358a02ef6d8eec5658a24644a4123e3a1
MD5 59a0d0bdf88ea4f80a18a83777fdf6fe
BLAKE2b-256 53dd6586f07a8957103677875d4acda7f9e0b2f114f80016b01a7eecbebb0c3e

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