11# Python Open Policy Agent (OPA) Client
22
3-
4-
3+ [ ![ Downloads] ( https://pepy.tech/badge/opa-python-client )] ( https://pepy.tech/project/opa-python-client )
54
65See offical documentation page [ Open Policy Agent] ( https://www.openpolicyagent.org/docs/latest/ )
76
@@ -57,6 +56,8 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
5756
5857client.check_connection() # response is Yes I'm here :)
5958
59+ # Ensure the connection is closed correctly by deleting the client
60+ del client
6061```
6162
6263
@@ -77,6 +78,7 @@ client = OpaClient(
7778
7879client.check_connection() # response is Yes I'm here :)
7980
81+ del client
8082```
8183
8284
@@ -93,6 +95,7 @@ client.update_opa_policy_fromfile("/your/path/filename.rego", endpoint="fromfile
9395
9496client.get_policies_list() # response is ["fromfile"]
9597
98+ del client
9699```
97100
98101
@@ -109,6 +112,7 @@ client.update_opa_policy_fromurl("http://opapolicyurlexample.test/example.rego",
109112
110113client.get_policies_list() # response is ["fromfile","fromurl"]
111114
115+ del client
112116```
113117
114118
@@ -126,6 +130,7 @@ client.delete_opa_policy("fromfile") # response is True
126130
127131client.get_policies_list() # response is [fromurl"]
128132
133+ del client
129134```
130135
131136### Get raw data from OPA service ###
@@ -140,6 +145,7 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
140145
141146print (client.get_opa_raw_data(" testapi/testdata" )) # response is {'result': ['world', 'hello']}
142147
148+ del client
143149```
144150
145151### Save policy to file from OPA service ###
@@ -154,7 +160,7 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
154160
155161client.opa_policy_to_file(policy_name = " fromurl" ,path = " /your/path" ,filename = " example.rego" ) # response is True
156162
157-
163+ del client
158164```
159165
160166### Delete data from OPA service ###
@@ -169,7 +175,7 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
169175
170176client.delete_opa_data(" testapi" ) # response is True
171177
172-
178+ del client
173179```
174180
175181
@@ -187,6 +193,7 @@ client.get_policies_info()
187193
188194# response is {'testpolicy': {'path': ['http://your-opa-service/v1/data/play'], 'rules': ['http://your-opa-service/v1/data/play/hello']}
189195
196+ del client
190197```
191198
192199
@@ -205,6 +212,7 @@ client.check_permission(input_data=permission_you_want_check, policy_name="testp
205212
206213# response is {'result': True}
207214
215+ del client
208216```
209217
210218
0 commit comments