Skip to main content

OPA WebAssembly SDK for Python based on wasmtime

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opa_wasmtime-0.1.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

opa_wasmtime-0.1.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file opa_wasmtime-0.1.1.tar.gz.

File metadata

  • Download URL: opa_wasmtime-0.1.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for opa_wasmtime-0.1.1.tar.gz
Algorithm Hash digest
SHA256 330d7dbf2a47e5c5c4ace269eeddabe339e3c61502e4a740b4786f93fe1b8e2d
MD5 271069b26295dfaa1a467cccd84b1ad1
BLAKE2b-256 526fdfdbd0b5543e25bb2ee0e89f2b01bc5b858369e105a6b1de196047f4b542

See more details on using hashes here.

File details

Details for the file opa_wasmtime-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for opa_wasmtime-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cfb6210c1d2f0b44d3346d65f4772f5e30b83397ced84264ef10a2a7ffabfe1c
MD5 d7f0257674b38ab08697dde4afd5560a
BLAKE2b-256 22a2b2f7ccaa0a30d3f0bb7af34d911ef8597ba757adb4d2961820c770073a8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page