Skip to main content

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

Project description

PyAPSI

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

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

Installation

From PyPI (builds from source)

pip install apsi

This downloads the source distribution and builds APSI + all dependencies locally. The build automatically selects the best CPU optimizations for your machine.

Requirements:

  • C++ compiler (GCC >= 9, Clang >= 10, or MSVC >= 2019)
  • CMake >= 3.13.4
  • Python >= 3.11
  • Internet access (vcpkg downloads dependencies during build)

Build time: Approximately 5-15 minutes depending on your machine.

Performance Note

On Linux x86_64, the FourQlib elliptic curve assembly optimizations are disabled because the hand-optimized AVX2 assembly files use non-PIC relocations that are incompatible with Python shared extensions (.so files). The generic C fallback is used instead, which results in approximately 2-3x slower OPRF (Oblivious Pseudorandom Function) operations.

This does not affect the SEAL homomorphic encryption operations, which dominate runtime for typical set intersection sizes. On macOS and Windows, FourQlib uses different optimization paths that are not affected.

For maximum performance on Linux, consider building APSI as a standalone static library outside of Python and using the native CLI tools.

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

From Source

pip install -e .
pytest tests/

Building a Source Distribution

pip install build
python -m build --sdist

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

apsi-0.2.1.tar.gz (16.9 kB view details)

Uploaded Source

File details

Details for the file apsi-0.2.1.tar.gz.

File metadata

  • Download URL: apsi-0.2.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apsi-0.2.1.tar.gz
Algorithm Hash digest
SHA256 572c89a3f1747a04b4d24ee252591f3e3a3b0948514f2c95c794e32f80a1e8f5
MD5 90d98c2297fd31cd3021857ae9529587
BLAKE2b-256 e716d1366b4b36ee2fe21c6e2a5ea0cb9d1c12a348412b66799fae71762c2a74

See more details on using hashes here.

Provenance

The following attestation bundles were made for apsi-0.2.1.tar.gz:

Publisher: build-sdist.yml on LGro/PyAPSI

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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