Skip to content
/ PyAPSI Public

Python wrapper for labeled and unlabeled asymmetric private set intersection (APSI).

License

Notifications You must be signed in to change notification settings

LGro/PyAPSI

Repository files navigation

PyAPSI

Actions Status PyPI - Wheel PyPI - Python Version License: MIT Code style: black

Python wrapper for labeled and unlabeled asymmetric private set intersection (APSI).

NOTE: This repository is not actively maintained right now, since my focus has shifted away from APSI. The most valuable contribution would be to set up deploying tarballs to PyPI that are pip installable and build APSI locally to match the available platform extensions.

Setup

For manylinux_2_31_x86_64 compatible platforms you can install PyAPSI from PyPi with

pip install apsi

You can check the system library versions that are required to be manylinux_2_31_x86_64 compatible in the auditwheel policy.

NOTE: While AVX2 supported is currently patched out (#11), APSI and its dependencies still seem to choose optimizations during build time depending on the available CPU flags, which can cause incompatibility of the pre-built wheels on older CPUs beyond what auditwheel can identify (#13).

In case you feel like contributing a build setup for Windows and OSX compatible wheels or extend the "From Source" section below, I would be happy to review your pull request.

Example

Example usage of the labeled APSI server and client. The unlabeled variant can be used analogous to this.

from apsi import LabeledServer, LabeledClient

apsi_params = """
{
    "table_params": {
        "hash_func_count": 3,
        "table_size": 512,
        "max_items_per_bin": 92
    },
    "item_params": {"felts_per_item": 8},
    "query_params": {
        "ps_low_degree": 0,
        "query_powers": [1, 3, 4, 5, 8, 14, 20, 26, 32, 38, 41, 42, 43, 45, 46]
    },
    "seal_params": {
        "plain_modulus": 40961,
        "poly_modulus_degree": 4096,
        "coeff_modulus_bits": [40, 32, 32]
    }
}
"""

server = LabeledServer()
server.init_db(apsi_params, max_label_length=10)
server.add_items([("item", "1234567890"), ("abc", "123"), ("other", "my label")])

client = LabeledClient(apsi_params)

oprf_request = client.oprf_request(["item", "abc"])
oprf_response = server.handle_oprf_request(oprf_request)
query = client.build_query(oprf_response)
response = server.handle_query(query)
result = client.extract_result(response)

assert result == {"item": "1234567890", "abc": "123"}

To control multi threading and logging in APSI see apsi.utils.

Building & Testing

Docker

Before you start, make sure that Taskfile, Docker and Poetry are installed.

You can then run a full build with tests that will generate a wheel file in dist/ as follows:

task wheel PYTHON_VERSION=3.10.4

Note: Only Python 3.8, 3.9, 3.10, and their patch versions for which official Python Docker images exist are supported.

From Source

Please have a look at the files inside docker/ for the required vcpkg setup and apsi AVX2 patch, in case you'd like to build from source in a custom environment.