1
1
# Python Open Policy Agent (OPA) Client
2
2
3
-
4
-
3
+ [ ![ Downloads] ( https://pepy.tech/badge/opa-python-client )] ( https://pepy.tech/project/opa-python-client )
5
4
6
5
See offical documentation page [ Open Policy Agent] ( https://www.openpolicyagent.org/docs/latest/ )
7
6
@@ -57,6 +56,8 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
57
56
58
57
client.check_connection() # response is Yes I'm here :)
59
58
59
+ # Ensure the connection is closed correctly by deleting the client
60
+ del client
60
61
```
61
62
62
63
@@ -77,6 +78,7 @@ client = OpaClient(
77
78
78
79
client.check_connection() # response is Yes I'm here :)
79
80
81
+ del client
80
82
```
81
83
82
84
@@ -93,6 +95,7 @@ client.update_opa_policy_fromfile("/your/path/filename.rego", endpoint="fromfile
93
95
94
96
client.get_policies_list() # response is ["fromfile"]
95
97
98
+ del client
96
99
```
97
100
98
101
@@ -109,6 +112,7 @@ client.update_opa_policy_fromurl("http://opapolicyurlexample.test/example.rego",
109
112
110
113
client.get_policies_list() # response is ["fromfile","fromurl"]
111
114
115
+ del client
112
116
```
113
117
114
118
@@ -126,6 +130,7 @@ client.delete_opa_policy("fromfile") # response is True
126
130
127
131
client.get_policies_list() # response is [fromurl"]
128
132
133
+ del client
129
134
```
130
135
131
136
### Get raw data from OPA service ###
@@ -140,6 +145,7 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
140
145
141
146
print (client.get_opa_raw_data(" testapi/testdata" )) # response is {'result': ['world', 'hello']}
142
147
148
+ del client
143
149
```
144
150
145
151
### Save policy to file from OPA service ###
@@ -154,7 +160,7 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
154
160
155
161
client.opa_policy_to_file(policy_name = " fromurl" ,path = " /your/path" ,filename = " example.rego" ) # response is True
156
162
157
-
163
+ del client
158
164
```
159
165
160
166
### Delete data from OPA service ###
@@ -169,7 +175,7 @@ client = OpaClient() # default host='localhost', port=8181, version='v1'
169
175
170
176
client.delete_opa_data(" testapi" ) # response is True
171
177
172
-
178
+ del client
173
179
```
174
180
175
181
@@ -187,6 +193,7 @@ client.get_policies_info()
187
193
188
194
# response is {'testpolicy': {'path': ['http://your-opa-service/v1/data/play'], 'rules': ['http://your-opa-service/v1/data/play/hello']}
189
195
196
+ del client
190
197
```
191
198
192
199
@@ -205,6 +212,7 @@ client.check_permission(input_data=permission_you_want_check, policy_name="testp
205
212
206
213
# response is {'result': True}
207
214
215
+ del client
208
216
```
209
217
210
218
0 commit comments