Skip to main content

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_data deep-merges objects; identical values coexist, conflicting values raise OpaError(code="merge_conflict") naming the conflicting path.
  • register_function infers arity from the callable's signature. A *args function 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.
  • Rego print(...) output is captured per evaluation: set engine.print_handler to a callable(message, location) to receive it (default: written to stderr); engine.last_prints holds 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

opa_golib_python_bindings-0.1.2.tar.gz (19.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_x86_64.whl (14.7 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ x86-64

opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_aarch64.whl (13.3 MB view details)

Uploaded Python 3manylinux: glibc 2.34+ ARM64

opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_x86_64.whl (8.3 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_arm64.whl (7.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file opa_golib_python_bindings-0.1.2.tar.gz.

File metadata

File hashes

Hashes for opa_golib_python_bindings-0.1.2.tar.gz
Algorithm Hash digest
SHA256 31c049c057bc9b935223ceb7ade8c38fc88235be8429c861a436799ac45d411d
MD5 29b1742798a21a553860dac40ee805a1
BLAKE2b-256 2b0f440e074d079ef3dcb3bf28f341a8fada9388f85ba795364cd9d778e8bb47

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_golib_python_bindings-0.1.2.tar.gz:

Publisher: publish.yml on phi1010/opa-golib-python-bindings

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

File details

Details for the file opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e37f627df2d9949dc544a6ddad22c913e00749657c2575024e44f9f74e624cd7
MD5 caf090ffaf2b5c38235b3c9c9f0e8ffe
BLAKE2b-256 4b16c06081ce74f8cfafa324d9777475c40f35c639221a5e4843191d138296c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_x86_64.whl:

Publisher: publish.yml on phi1010/opa-golib-python-bindings

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

File details

Details for the file opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f2c725d8541fefffe3f6cc6044ddc5a0bee4452f7e6ada943bd78d270a753805
MD5 29bb918c6c369df4759a6f7e3bfc93e3
BLAKE2b-256 f256347566916cb4f9bbf6fe72dbba774244f0dbe0cb01df6ccda7b21e5f8184

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_golib_python_bindings-0.1.2-py3-none-manylinux_2_34_aarch64.whl:

Publisher: publish.yml on phi1010/opa-golib-python-bindings

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

File details

Details for the file opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 987e2838a9231dbf32423ab31613070ebc9970acd3925ae320191539acdb82ce
MD5 4ddb1f593d1ab559c8ad78c30d5466b2
BLAKE2b-256 a67e9f99187a5c20492674ae61a174985416123af9aeecc5cc17ffcc56749639

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_x86_64.whl:

Publisher: publish.yml on phi1010/opa-golib-python-bindings

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

File details

Details for the file opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f9034a38bc1dfa8eb9fa07885eb03c4f74e08a7b422dadcea70d038f1baca9eb
MD5 1d5a884d968a182b3064fb955eba9691
BLAKE2b-256 cdeb66e6430a663d18049bb3d4a6a8385a965effb488cba8d03701ad8c0b0816

See more details on using hashes here.

Provenance

The following attestation bundles were made for opa_golib_python_bindings-0.1.2-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on phi1010/opa-golib-python-bindings

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

Release history Release notifications | RSS feed

0.3.0

5 files

0.2.0

5 files

This release

0.1.2 This release

5 files

0.1.0

5 files

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