opa-golib-python-bindings
Python bindings for the OPA Rego engine, embedding
github.com/open-policy-agent/opa/v1/rego via a Go c-shared library and a stdlib-only
ctypes wrapper.
Build
Requires Go >= 1.26 and Python >= 3.14.
make build # builds src/opa_bindings/libopabridge.so
make test # builds + runs pytest
Usage
from opa_bindings import OpaEngine
users = {"alice": {"role": "admin"}}
with OpaEngine() as engine:
engine.add_policy("authz.rego", """
package authz
allow if lookup_user(input.user).role == "admin"
""")
engine.add_data({"admin": ["alice"]}, path="roles") # deep-merged; conflicts raise
engine.register_function("lookup_user", lambda name: users.get(name))
engine.eval_document("authz.allow", {"user": "alice"}) # -> True
engine.eval_query("x = data.roles.admin[_]") # -> [{"x": "alice"}]
Notes:
add_datadeep-merges objects; identical values coexist, conflicting values raiseOpaError(code="merge_conflict")naming the conflicting path.register_functioninfers arity from the callable's signature. A*argsfunction is variadic and is called from Rego with a single array argument:many(["a", "b"])(OPA does not support variadic builtins with return values).- Builtin arguments and return values are JSON-compatible objects. A callback exception becomes an evaluation error; returning is fine.
- An undefined document raises
OpaUndefinedError. - Pass
coverage=Truetoeval_document/eval_queryto capture a coverage report (OPA'scovertracer) inengine.last_coverage: per-filecovered/not_coveredline ranges plus line counts and a coverage percentage over all added policies. Evaluating withoutcoverage=Trueresets it toNone. - Pass
trace=Trueto capture the full evaluation trace inengine.last_trace: a list of event dicts (op,location,node,locals, ...) in evaluation order.localsholds the plugged variable bindings live at each step, so the value a statement produced is visible (e.g.{"x": 6}afterx := input.n * 2); a false condition appears as aFailevent at its location. An undefined document still carries its trace — the main way to see which condition failed. Note thatnodeshows the compiler-rewritten expression (temporaries like__local0__), a statement may appear multiple times (Redoon backtracking), and tracing slows evaluation, so keep it opt-in per call. Coverage only records which statements were evaluated; traces are how to see their results. - Rego
print(...)output is captured per evaluation: setengine.print_handlerto acallable(message, location)to receive it (default: written to stderr);engine.last_printsholds the(message, location)pairs of the last eval.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
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 opa_golib_python_bindings-0.2.0.tar.gz.
File metadata
- Download URL: opa_golib_python_bindings-0.2.0.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
db3a9dda91363e7b6d5835bbbf5d0df3fb439fa7289b99c25c383e2cc8947237
|
|
| MD5 |
09312e8da1eb3f005eacd39ebecec9e9
|
|
| BLAKE2b-256 |
a7a40140a9e263cd9b7c985d99aad21c1473502696eafa7bdb132bd8e37d7489
|
Provenance
The following attestation bundles were made for opa_golib_python_bindings-0.2.0.tar.gz:
Publisher:
publish.yml on phi1010/opa-golib-python-bindings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_golib_python_bindings-0.2.0.tar.gz -
Subject digest:
db3a9dda91363e7b6d5835bbbf5d0df3fb439fa7289b99c25c383e2cc8947237 - Sigstore transparency entry: 2589333496
- Sigstore integration time:
-
Permalink:
phi1010/opa-golib-python-bindings@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Branch / Tag:
refs/tags/release/v0.2.0-opa1.19.1 - Owner: https://github.com/phi1010
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 14.7 MB
- Tags: Python 3, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f54150295927509cac7bf5fd19de1d1c4ac8f80028fd144f6b37da9018442164
|
|
| MD5 |
7dcdafa1467f9ea0f9a5065c1ffbc857
|
|
| BLAKE2b-256 |
11a3ad471bb6bfa07ffae35eee13b9d06ba55913c8387d6a1c42d60dd088dade
|
Provenance
The following attestation bundles were made for opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_x86_64.whl:
Publisher:
publish.yml on phi1010/opa-golib-python-bindings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_x86_64.whl -
Subject digest:
f54150295927509cac7bf5fd19de1d1c4ac8f80028fd144f6b37da9018442164 - Sigstore transparency entry: 2589335992
- Sigstore integration time:
-
Permalink:
phi1010/opa-golib-python-bindings@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Branch / Tag:
refs/tags/release/v0.2.0-opa1.19.1 - Owner: https://github.com/phi1010
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 13.4 MB
- Tags: Python 3, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11237543ba9ae78c75e4aad8beffb2f9ffba24365dd50052ea9c548dc9af69e6
|
|
| MD5 |
d959c09f58d90387572be8b82f7b8f34
|
|
| BLAKE2b-256 |
56b60936e7182115b26686fd62d9e9057a71af328979c05598c2223270bad9c4
|
Provenance
The following attestation bundles were made for opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_aarch64.whl:
Publisher:
publish.yml on phi1010/opa-golib-python-bindings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_golib_python_bindings-0.2.0-py3-none-manylinux_2_34_aarch64.whl -
Subject digest:
11237543ba9ae78c75e4aad8beffb2f9ffba24365dd50052ea9c548dc9af69e6 - Sigstore transparency entry: 2589333671
- Sigstore integration time:
-
Permalink:
phi1010/opa-golib-python-bindings@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Branch / Tag:
refs/tags/release/v0.2.0-opa1.19.1 - Owner: https://github.com/phi1010
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_x86_64.whl.
File metadata
- Download URL: opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_x86_64.whl
- Upload date:
- Size: 8.3 MB
- Tags: Python 3, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2289a271e8db5d76d691c7c7dffa6a90e1ecb85a7d12be54017db425f4c79e21
|
|
| MD5 |
e0ef5ecbedf7177d5815aaeb51e1636c
|
|
| BLAKE2b-256 |
f2329ee393b04f350e517fdead0fa02361a1e438ae6e5a7433fe31b2fa2c9526
|
Provenance
The following attestation bundles were made for opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_x86_64.whl:
Publisher:
publish.yml on phi1010/opa-golib-python-bindings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_x86_64.whl -
Subject digest:
2289a271e8db5d76d691c7c7dffa6a90e1ecb85a7d12be54017db425f4c79e21 - Sigstore transparency entry: 2589333551
- Sigstore integration time:
-
Permalink:
phi1010/opa-golib-python-bindings@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Branch / Tag:
refs/tags/release/v0.2.0-opa1.19.1 - Owner: https://github.com/phi1010
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Trigger Event:
release
-
Statement type:
File details
Details for the file opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 7.6 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6b3a9d4288bb501a8aed49a48a5c3475176804e70a7193dbd0c05b93e5acb5d
|
|
| MD5 |
11a894ef41b8ca93c1a3c75b95b7a1c4
|
|
| BLAKE2b-256 |
65a811d7f599464ad4829721dc772ef5c83d0c1204745ebe71c2170983a00ed4
|
Provenance
The following attestation bundles were made for opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish.yml on phi1010/opa-golib-python-bindings
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
opa_golib_python_bindings-0.2.0-py3-none-macosx_11_0_arm64.whl -
Subject digest:
e6b3a9d4288bb501a8aed49a48a5c3475176804e70a7193dbd0c05b93e5acb5d - Sigstore transparency entry: 2589335032
- Sigstore integration time:
-
Permalink:
phi1010/opa-golib-python-bindings@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Branch / Tag:
refs/tags/release/v0.2.0-opa1.19.1 - Owner: https://github.com/phi1010
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9b188c6ebad1e9c390c384e257184da7f95c2533 -
Trigger Event:
release
-
Statement type: