OpenMined Private Set Intersection (PSI)
OpenMined PSI (Private Set Intersection) is a cryptographic library that allows two parties to compute the intersection of their private datasets without revealing non-intersecting elements. It focuses on securely computing the *size* of the intersection. The library is currently at version 2.0.6 and is actively maintained with frequent minor updates for dependency bumps and Python version support.
Common errors
-
ModuleNotFoundError: No module named 'psi'
cause The Python package name was changed from `psi` to `openmined_psi` in version 2.0.3.fixChange your import statements from `import psi` or `from psi import ...` to `import openmined_psi` or `from openmined_psi import ...`. -
AttributeError: module 'openmined_psi.client' has no attribute 'GetIntersection'
cause The `openmined-psi` library only provides the `GetIntersectionSize` method for privacy reasons, not methods to retrieve the actual intersecting elements.fixUse `client_psi.GetIntersectionSize(response)` to obtain the size of the intersection. If you require the actual elements, this library is not suitable.
Warnings
- breaking The Python package was renamed from `psi` to `openmined_psi` in version 2.0.3. Older import statements will fail.
- gotcha The `openmined-psi` library is designed for privacy-preserving computation and will only return the *size* of the intersection, not the intersecting elements themselves. Attempting to retrieve the actual elements will result in an error or unexpected behavior.
- gotcha The library requires Python 3.9 or higher. Installing or running `openmined-psi` on older Python versions (e.g., 3.8) will lead to installation failures or runtime errors.
Install
-
pip install openmined-psi
Imports
- client
from psi import client
from openmined_psi import client
- server
from psi import server
from openmined_psi import server
Quickstart
from openmined_psi import client, server
# Setup common inputs
client_inputs = ["client@example.com", "client2@example.com", "test@example.com"]
server_inputs = ["client@example.com", "server@example.com", "test@example.com"]
# --- Server side ---
# Create a server instance (e.g., with a new key)
server_psi = server.CreateWithNewKey(False) # 'False' means not to reveal the server's key
# Create a setup message. The first parameter is the FPR (False Positive Rate),
# the second is the number of elements in the server's set.
setup_message = server_psi.CreateSetupMessage(0.001, len(server_inputs), server_inputs)
# --- Client side ---
# Create a client instance
client_psi = client.CreateWithNewKey(False) # 'False' means not to reveal the client's key
# Create a request message from the client's inputs
request = client_psi.CreateRequest(client_inputs)
# --- Server side (handling request) ---
# Server handles the client's request
response = server_psi.HandleRequest(request)
# --- Client side (getting intersection size) ---
# Client processes the server's response to get the intersection size.
# Note: openmined-psi only provides the intersection *size* for privacy reasons,
# not the actual elements themselves.
intersection_size = client_psi.GetIntersectionSize(response)
print(f"Intersection size: {intersection_size}") # Expected: 2 (client@example.com, test@example.com)