Skip to main content

OPA WebAssembly SDK for Python based on wasmtime

This is based off opa-wasm, which uses wasmer, but this targets wasmtime. This allows you to use OPA WASM binaries in Python versions above 3.10, which is the cutoff for wasmer.

It also appears to run significantly faster due to some optimizations I made and some optimizations in python in general since 3.10.

Getting Started

Install the module

pip install opa-wasmtime

Usage

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

# Import the module
from opa_wasmtime 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)

Support Targets

This module has been tested on python 3.10 and above and wasmtime 27.0.2 and above.

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.

Metadata

Release files for opa-wasmtime 0.1.1

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-wasmtime 0.1.1
File Size Uploaded
opa_wasmtime-0.1.1.tar.gz 6.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opa-wasmtime 0.1.1
File Interpreter ABI Platform
opa_wasmtime-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 12.4 kB

Release files / opa_wasmtime-0.1.1.tar.gz

Download URL opa_wasmtime-0.1.1.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
330d7dbf2a47e5c5c4ace269eeddabe339e3c61502e4a740b4786f93fe1b8e2d
BLAKE2b-256 checksum
How to use checksums
526fdfdbd0b5543e25bb2ee0e89f2b01bc5b858369e105a6b1de196047f4b542
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Release files / opa_wasmtime-0.1.1-py3-none-any.whl

Download URL opa_wasmtime-0.1.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfb6210c1d2f0b44d3346d65f4772f5e30b83397ced84264ef10a2a7ffabfe1c
BLAKE2b-256 checksum
How to use checksums
22a2b2f7ccaa0a30d3f0bb7af34d911ef8597ba757adb4d2961820c770073a8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.9

Release history Release notifications | RSS feed

This release

0.1.1 This release

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