Skip to main content

Client for connection to the OPA service

Project description

Python Open Policy Agent (OPA) Client

See offical documentation page Open Policy Agent

>>> from opa_client.opa import OpaClient
>>> client = OpaClient() # default host='localhost', port=8181, version='v1'
>>> print(client.check_connection())
True
>>>  test_policy = """
...     package play
... 
...     import data.testapi.testdata
... 
...     default hello = false
... 
...     hello {
...         m := input.message
...         testdata[i] == "world"
...     }
... """

>>> print(client.update_opa_policy_fromstring(test_policy, "testpolicy"))
True
>>> print(client.get_policies_list())
['testpolicy']
>>> data = ["world", "hello"]
>>> print(client.update_or_create_opa_data(data, "testapi/testdata"))
True
>>> check_data = {"input": {"message": "hello"}}
>>> print(client.check_permission(input_data=check_data, policy_name="testpolicy", rule_name="hello"))
{'result': True}

OPA-python-client supports Python >= 3.6

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-python-client-1.0.1.tar.gz (4.3 kB view hashes)

Uploaded Source

Built Distribution

OPA_python_client-1.0.1-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

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