Skip to main content

PrivyQ Python SDK (privyq)

The developer-facing interface to PrivyQ. It hides all cryptographic and gRPC detail behind three verbs, protect(), access(), verify(), so you think in terms of business intent, not primitives.

import privyq

privyq.configure(core_address="localhost:50051")

# Lock a record, attaching the access rules in the same call.
protected = privyq.protect(
    "Patient: John Doe. Plan: continue beta-blocker.",
    policy={"role": "doctor", "department": "cardiology", "purpose": "treatment", "expiry": "24h"},
    actor={"user_id": "dr_smith", "role": "doctor", "department": "cardiology"},
)

# Open it, only if the policy is satisfied.
result = privyq.access(protected, identity={"role": "doctor", "department": "cardiology", "purpose": "treatment"})
print(result.text)          # -> "Patient: John Doe. ..."
print(result.receipt.id)    # a signed, verifiable access receipt

# Verify the receipt cryptographically.
check = privyq.verify(result.receipt)
assert check.ok and check.signature_valid and check.chain_valid

Denied access raises PolicyViolationError, and the attempt is still recorded as tamper-evident evidence:

try:
    privyq.access(protected, identity={"role": "nurse"})
except privyq.PolicyViolationError as why:
    print(why)   # -> "policy violation: role condition failed ..."

Installation

pip install privyq            # from PyPI (once published)
pip install -e ".[dev]"       # from this repo, with test/lint extras

The SDK talks to a running PrivyQ core (privyqd). Point it at the core with configure(core_address=...) or the PRIVYQ_CORE_ADDRESS env var.

Policy shorthand

Policies accept two forms. The shorthand maps each key to a condition, lists become in, expiry becomes a before with duration expansion ("24h" → an absolute timestamp):

{"role": "doctor", "department": ["cardiology", "oncology"], "expiry": "24h"}

The structured form is explicit and supports every operator (BP App D):

{"conditions": [{"type": "role", "operator": "in", "value": ["doctor", "specialist"]}],
 "combination": "all"}

API surface

Function Purpose
configure(**opts) Set core address, default algorithms, timeout, TLS
protect(data, policy, *, actor, key_id, algorithm) Encrypt with an embedded policy
access(protected, identity, *, context) Decrypt if the policy allows; else raise
verify(receipt) Verify a receipt's signature and chain linkage
evidence.log(*, resource_id, actor_id, ...) Retrieve audit receipts
generate_key / rotate_key / revoke_key Key lifecycle

Exceptions follow a hierarchy rooted at PrivyQError (PolicyViolationError, KeyNotFoundError, CryptoError, CoreUnreachableError, …).

Configuration (ARCH §20.3)

Env var Default
PRIVYQ_CORE_ADDRESS localhost:50051
PRIVYQ_ALGORITHM kyber_768
PRIVYQ_SIGNATURE dilithium_3
PRIVYQ_TIMEOUT 5
PRIVYQ_AUDIT true

Development

pip install -e ".[dev]"
pytest -q          # unit tests + integration (builds & launches the real core)
black privyq

The gRPC stubs under privyq/_proto/ are generated from core-go/pkg/proto/privyq.proto. Regenerate with ../scripts/gen-python-proto.sh (or make proto at the repo root).

Metadata

Release files for privyq 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for privyq 1.0.0
File Size Uploaded Provenance Actions
privyq-1.0.0.tar.gz 17.7 kB Without provenance Details for privyq-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for privyq 1.0.0
File Interpreter ABI Platform Actions
privyq-1.0.0-py3-none-any.whl Python 3 none any Details for privyq-1.0.0-py3-none-any.whl

Total release size: 36.1 kB

Release files / privyq-1.0.0.tar.gz

Download URL privyq-1.0.0.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
319bc12e2735fa21ccefcac9aeeb0daf0b06f9fe2d64be175a809292b8b6d1e9
BLAKE2b-256 checksum
How to use checksums
9cd7c5dc88d56e63238d548d6dde0888d2ffe1e2f0522ab1c97397581826ba7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / privyq-1.0.0-py3-none-any.whl

Download URL privyq-1.0.0-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
495b9680912c77b6aac839d4d47e0fe7a172c20e9e9d6758283f8752c084b3db
BLAKE2b-256 checksum
How to use checksums
22ba3cdd20547be07e047c44da9b86f43ac1647685011ec685aa6b5901be0a49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for privyq 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page