Post-quantum, policy-governed encryption with verifiable privacy evidence
Project description
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).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file privyq-1.0.0.tar.gz.
File metadata
- Download URL: privyq-1.0.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
319bc12e2735fa21ccefcac9aeeb0daf0b06f9fe2d64be175a809292b8b6d1e9
|
|
| MD5 |
fc9c70e11e27aeb68fd796fd2819bd42
|
|
| BLAKE2b-256 |
9cd7c5dc88d56e63238d548d6dde0888d2ffe1e2f0522ab1c97397581826ba7e
|
File details
Details for the file privyq-1.0.0-py3-none-any.whl.
File metadata
- Download URL: privyq-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
495b9680912c77b6aac839d4d47e0fe7a172c20e9e9d6758283f8752c084b3db
|
|
| MD5 |
afc69623da8104ba5e146135c030bfc9
|
|
| BLAKE2b-256 |
22ba3cdd20547be07e047c44da9b86f43ac1647685011ec685aa6b5901be0a49
|