Releases: Turall/OPA-python-client
Release list
v2.1.0
Changelog
All notable changes to this project will be documented in this file.
[v2.1.0]
Added
OpaClient.compile_query/AsyncOpaClient.compile_query— support for OPA's
Compile API (POST /v1/compile), enabling partial evaluation of a query against
a chosen set of unknowns (e.g. compiling a policy into a residual filter for
use withdata.reports-style authorization-as-filter patterns).AsyncOpaClientnow retries requests on connection errors and on500/502/504
responses, honoring theretriesoption the same way the sync client's
urllib3.Retry-backed session already did.OpaClient.get_config/AsyncOpaClient.get_config— support for OPA's
GET /v1/configendpoint, returning the server's active configuration.OpaClient.get_metrics/AsyncOpaClient.get_metrics— support for OPA's
GET /metricsendpoint, returning Prometheus-formatted performance metrics.OpaClient.patch_data/AsyncOpaClient.patch_data— support forPATCH /v1/data,
enabling partial updates to existing data using a JSON Patch (RFC 6902) document
instead of overwriting the whole document.
Changed
AsyncOpaClientnow inherits fromBaseClient, removing ~70 lines of duplicated
property boilerplate and sharing the Rego-compat helper methods with the sync client.
Fixed
-
AsyncOpaClient.update_or_create_dataraisedAttributeErrorinstead of
RegoParseErroron a400response, becauseAsyncOpaClientdid not inherit
BaseClientand therefore lacked_raise_rego_parse_error. -
AsyncOpaClient.check_permissionsent requests to a duplicated/v1/data/data/...
endpoint (the AST-derived package path already includes a leadingdatasegment),
causing it to silently return an empty result instead of the permission decision. -
AsyncOpaClientraisedTypeErrorinstead of the intended exception in several
error paths (update_policy_from_file,policy_to_file,check_permission) because
FileError,PolicyNotFoundError,PathNotFoundError, andCheckPermissionError
were called with only one of their two required constructor arguments. -
OpaClient.ad_hoc_queryandAsyncOpaClient.ad_hoc_querynow send the ad hoc query
andinputdocument in the JSON body of aPOST /v1/queryrequest, matching OPA's
REST API contract, instead of mixing a GET-styleqquery parameter with an
unrelated JSON body.
v2.0.5
v2.0.5
OPA 1.0+ compatibility
OPA 1.0 enforces Rego v1 syntax. Policies written in the legacy v0 style (for example allow { ... }) fail to compile with errors such as:
ifkeyword is required before rule body
This release adds automatic backward-compatible handling when uploading policies.
Auto-upgrade on upload
update_policy_from_string(..., rego_compat=True) is now the default behavior:
- Upload the policy as-is (works with OPA 0.x and v0 Rego).
- If OPA rejects it due to v0 syntax, upgrade common constructs and retry.
Supported upgrades:
| v0 syntax | v1 syntax |
|---|---|
allow { ... } |
allow if { ... } |
deny[msg] { ... } |
deny contains msg if { ... } |
Compatibility matrix
| Server | v0 policy | v1 policy |
|---|---|---|
| OPA 0.x | Works on first upload | Works |
| OPA 1.0+ | Auto-upgraded and retried | Works on first upload |
To disable auto-upgrade:
client.update_policy_from_string(policy, "my_policy", rego_compat=False)Improvements
RegoParseErrornow includes OPA’s detailederrorslist in the exception message.AsyncOpaClient.update_policy_from_stringnow sends the correctContent-Type: text/plainheader.- README and CONTRIBUTING updated with Rego v1 examples and OPA version guidance.
Dependencies
aiohttp^3.14.1requests^2.34.2urllib3^2.7.0
Upgrade notes
-
New policies: use Rego v1 syntax (
allow if { ... }). -
Existing v0 policies: no code changes required; the client upgrades them on upload by default.
-
Integration tests: require a running OPA server; compatible with OPA 0.x and 1.0+.
-
Legacy OPA mode: run OPA with
--v0-compatibleif you need strict v0 behavior:docker run -it --rm -p 8181:8181 openpolicyagent/opa run --server --addr :8181 --v0-compatible
v2.0.4
Update dependencies to fix vulnerabilities
Full Changelog: v2.0.3...v2.0.4
v2.0.3
What's Changed
- Fix BaseClient not respecting retries and timeout by @TheRealHaoLiu in #30
- fix issue #32 by @Turall in #33
- fix issue #31 by @Turall in #34
New Contributors
- @TheRealHaoLiu made their first contribution in #30
Full Changelog: v2.0.2...v2.0.3