Skip to main content

Open Policy Agent WebAssembly SDK for Python

This is the source for the opa-wasm Python module which is an SDK for using WebAssembly (wasm) compiled Open Policy Agent Rego policies using wasmer-python.

Getting Started

Install the module

You may choose to use either the cranelift or llvm compiler package as follows:

pip install opa-wasm[cranelift]

or

pip install opa-wasm[llvm]

For builds that target AWS Lambda as an execution environment, it is recommended to use cranelift. This avoids the need to bundle additional binary dependencies as part of the lambda package.

See the wasmer-python docs for more information

Usage

There are only a couple of steps required to start evaluating the policy.

# Import the module
from opa_wasm import OPAPolicy

# Load a policy by specifying its file path
policy = OPAPolicy('./policy.wasm')

# Optional: Set policy data
policy.set_data({"company_name": "ACME"})

# Evaluate the policy
input = {"user": "alice"}
result = policy.evaluate(input)

Writing the policy

See https://www.openpolicyagent.org/docs/latest/how-do-i-write-policies/

Compiling the policy

Either use the Compile REST API or opa build CLI tool.

For example, with OPA v0.20.5+:

opa build -t wasm -e 'example/allow' example.rego

Which compiles the example.rego policy file with the result set to data.example.allow. The result will be an OPA bundle with the policy.wasm binary included.

See opa build --help for more details.

Credits

This project was inspired by the equivalent NPM Module @open-policy-agent/opa-wasm

Metadata

Release files for opa-wasm 0.3.2

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

Source distribution (sdist)

Source distribution for opa-wasm 0.3.2
File Size Uploaded
opa-wasm-0.3.2.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opa-wasm 0.3.2
File Interpreter ABI Platform
opa_wasm-0.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.2 kB

Release files / opa-wasm-0.3.2.tar.gz

Download URL opa-wasm-0.3.2.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
377e530d54331f6d4b6e3e093900c4899c86d052b8d7267b8557353f182f4181
BLAKE2b-256 checksum
How to use checksums
25cb33058dc5f4cf8d422d5ca39391b2703ea6954e3e37ba783a7c232143b5da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.8.5 Linux/4.19.0-18-amd64

Release files / opa_wasm-0.3.2-py3-none-any.whl

Download URL opa_wasm-0.3.2-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f6720002de873a64281710216b2301c7325fc3c1d36c5f8f72da8c6ba72ab00
BLAKE2b-256 checksum
How to use checksums
97e3781c9b91b620c25cde8a0f2d5f13115d198e24caa1fda912be8545692766
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.11 CPython/3.8.5 Linux/4.19.0-18-amd64

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files

0.3.1

2 release files

0.2.0

2 release files

0.1.0

2 release 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