Skip to content

fix issue #31 #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,31 +354,7 @@ await client.delete_data('users')

#### Check Permission (Policy Evaluation)

You can evaluate policies with input data using `check_permission`.

- **Synchronous**:

```python
input_data = {"user": "admin"}
policy_name = 'example_policy'
rule_name = 'allow'

result = client.check_permission(input_data, policy_name, rule_name)
print(result)
```

- **Asynchronous**:

```python
input_data = {"user": "admin"}
policy_name = 'example_policy'
rule_name = 'allow'

result = await client.check_permission(input_data, policy_name, rule_name)
print(result)
```

Queries a package rule with the given input data
Evaluate a rule from a known package path. This is the **recommended method** for evaluating OPA decisions.

```python

Expand Down Expand Up @@ -422,6 +398,39 @@ print(await client.query_rule(input_data=check_data, package_path="play", rule_n

```

You can evaluate policies with input data using `check_permission`.
### ⚠️ Deprecated: `check_permission()`

This method introspects the policy AST to construct a query path dynamically. It introduces unnecessary overhead and is **not recommended** for production use.

- **Synchronous**:

```python
input_data = {"user": "admin"}
policy_name = 'example_policy'
rule_name = 'allow'

result = client.check_permission(input_data, policy_name, rule_name)
print(result)
```
> 🔥 Prefer `query_rule()` instead for better performance and maintainability.

### ⚠️ Deprecated: `check_permission()`

- **Asynchronous**:

```python
input_data = {"user": "admin"}
policy_name = 'example_policy'
rule_name = 'allow'

result = await client.check_permission(input_data, policy_name, rule_name)
print(result)
```
> 🔥 Prefer `query_rule()` instead for better performance and maintainability.



### Ad-hoc Queries

Execute ad-hoc queries directly:
Expand Down
6 changes: 6 additions & 0 deletions opa_client/opa.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import threading
import warnings
from typing import Dict, Optional
from urllib.parse import urlencode

Expand Down Expand Up @@ -391,6 +392,11 @@ def check_permission(
Returns:
dict: The result of the permission check.
"""
warnings.warn(
"check_permission is deprecated and will be removed in a future release. Use `query_rule` instead.",
DeprecationWarning,
stacklevel=2
)
policy = self.get_policy(policy_name)
ast = policy.get("result", {}).get("ast", {})
package_path = "/".join(
Expand Down
7 changes: 6 additions & 1 deletion opa_client/opa_async.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
import json
import warnings
import os
import ssl
from typing import Dict, Optional, Union
Expand Down Expand Up @@ -422,6 +422,11 @@ async def check_permission(
Returns:
dict: The result of the permission check.
"""
warnings.warn(
"check_permission is deprecated and will be removed in a future release. Use `query_rule` instead.",
DeprecationWarning,
stacklevel=2
)
policy = await self.get_policy(policy_name)
ast = policy.get("result", {}).get("ast", {})
package_path = "/".join(
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ python = "^3.9"
requests = "^2.32.3"
aiohttp = {extras = ["speedups"], version = "^3.10.9"}
aiofiles = "^24.1.0"
urllib3 = "^2.5.0"

[tool.poetry.group.dev.dependencies]
pytest = "^8.3.3"
Expand Down