{"library":"pyhpke","title":"Python HPKE Implementation","description":"PyHPKE is a Python implementation of HPKE (Hybrid Public Key Encryption), providing mechanisms for authenticated encryption with associated data. It supports all HPKE modes and cipher suites defined in RFC9180. The library is currently at version 0.6.4 and maintains a regular release cadence with frequent minor updates and dependency bumps.","language":"python","status":"active","last_verified":"Fri May 15","install":{"commands":["pip install pyhpke"],"cli":null},"imports":["from pyhpke import CipherSuite","from pyhpke import KEMKey","from pyhpke import KEMId","from pyhpke import KDFId","from pyhpke import AEADId"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pyhpke import CipherSuite, KEMKey, KEMId, KDFId, AEADId\n\n# --- Sender Side ---\n# Define the HPKE cipher suite\nsuite_s = CipherSuite.new(\n    KEMId.DHKEM_X25519_HKDF_SHA256,\n    KDFId.HKDF_SHA256,\n    AEADId.AES128_GCM\n)\n\n# Recipient's public key (example PEM format)\npublic_key_pem = b\"\"\"-----BEGIN PUBLIC KEY-----\nMCowBQYDK2VuAyEAoMfvlI5DN08JRFP2fhWvZ6vBEl28yFeS9O9YQUjNyCY=\n-----END PUBLIC KEY-----\"\"\"\npkr = KEMKey.from_pem(public_key_pem)\n\n# Create sender context and encapsulate key\nenc, sender = suite_s.create_sender_context(pkr)\n\n# Seal the message\nplaintext = b\"Hello world!\"\nciphertext = sender.seal(plaintext)\n\nprint(f\"Encapsulated Key: {enc.hex()}\")\nprint(f\"Ciphertext: {ciphertext.hex()}\")\n\n# --- Recipient Side ---\n# Define the same HPKE cipher suite\nsuite_r = CipherSuite.new(\n    KEMId.DHKEM_X25519_HKDF_SHA256,\n    KDFId.HKDF_SHA256,\n    AEADId.AES128_GCM\n)\n\n# Recipient's private key (example PEM format, corresponding to public_key_pem)\nprivate_key_pem = b\"\"\"-----BEGIN PRIVATE KEY-----\nMC4CAQAwBQYDK2VuBCIEIMAXvyHjAeXy9x4MXF6rwGbDKw7crgDriFTFXO+XsS1F\n-----END PRIVATE KEY-----\"\"\"\nskr = KEMKey.from_pem(private_key_pem)\n\n# Create recipient context and decapsulate key (using 'enc' from sender)\nrecipient = suite_r.create_recipient_context(enc, skr)\n\n# Open the message\ndecrypted_text = recipient.open(ciphertext)\n\nprint(f\"Decrypted Text: {decrypted_text.decode()}\")\nassert decrypted_text == plaintext","lang":"python","description":"This example demonstrates a basic HPKE 'Base' mode encryption and decryption flow. A sender creates a context using the recipient's public key, encapsulates a symmetric key, and seals a plaintext message. The recipient uses the encapsulated key and their private key to open the ciphertext.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-15","installed_version":"0.6.3","pypi_latest":"0.6.4","is_stale":true,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.3,"avg_import_s":0.1,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.08,"mem_mb":3,"disk_size":"33.5M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.4,"import_time_s":0.06,"mem_mb":3,"disk_size":"34M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.12,"mem_mb":3.4,"disk_size":"35.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.2,"import_time_s":0.11,"mem_mb":3.4,"disk_size":"36M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.11,"mem_mb":3.4,"disk_size":"27.4M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2,"import_time_s":0.11,"mem_mb":3.4,"disk_size":"28M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.13,"mem_mb":3.6,"disk_size":"27.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.1,"import_time_s":0.1,"mem_mb":3.4,"disk_size":"28M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.1,"mem_mb":3,"disk_size":"33.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"pyhpke","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0.08,"mem_mb":3,"disk_size":"34M"}]}}