brynq-sdk-brynq 1.1.0__tar.gz → 2.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of brynq-sdk-brynq might be problematic. Click here for more details.
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/PKG-INFO +1 -1
- brynq_sdk_brynq-2.0.1/brynq_sdk/brynq/__init__.py +1 -0
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/PKG-INFO +1 -1
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/SOURCES.txt +0 -1
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/setup.py +3 -4
- brynq_sdk_brynq-1.1.0/brynq_sdk/brynq/__init__.py +0 -1
- brynq_sdk_brynq-1.1.0/brynq_sdk/brynq/brynq.py +0 -273
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/dependency_links.txt +0 -0
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/not-zip-safe +0 -0
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/requires.txt +0 -0
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/top_level.txt +0 -0
- {brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from brynq_sdk_brynq.brynq import *
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
from setuptools import setup
|
|
2
|
-
|
|
1
|
+
from setuptools import setup, find_namespace_packages
|
|
3
2
|
|
|
4
3
|
setup(
|
|
5
4
|
name='brynq_sdk_brynq',
|
|
6
|
-
version='
|
|
5
|
+
version='2.0.1',
|
|
7
6
|
description='BrynQ SDK for the BrynQ.com platform',
|
|
8
7
|
long_description='BrynQ SDK for the BrynQ.com platform',
|
|
9
8
|
author='BrynQ',
|
|
10
9
|
author_email='support@brynq.com',
|
|
11
|
-
packages=[
|
|
10
|
+
packages=find_namespace_packages(include=['brynq_sdk*']),
|
|
12
11
|
license='BrynQ License',
|
|
13
12
|
install_requires=[
|
|
14
13
|
'requests>=2,<=3'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from brynq_sdk.brynq.brynq import BrynQ
|
|
@@ -1,273 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import requests
|
|
3
|
-
import json
|
|
4
|
-
import pandas as pd
|
|
5
|
-
from typing import Union, Literal
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class BrynQ:
|
|
9
|
-
def __init__(self, subdomain: str = None, api_token: str = None, staging: str = 'prod'):
|
|
10
|
-
self.subdomain = os.getenv("BRYNQ_SUBDOMAIN", subdomain)
|
|
11
|
-
self.api_token = os.getenv("BRYNQ_API_TOKEN", api_token)
|
|
12
|
-
self.environment = os.getenv("BRYNQ_ENVIRONMENT", staging)
|
|
13
|
-
|
|
14
|
-
if any([self.subdomain is None, self.api_token is None]):
|
|
15
|
-
raise ValueError("Set the subdomain, api_token either in your .env file or provide the subdomain and api_token parameters")
|
|
16
|
-
|
|
17
|
-
possible_environments = ['dev', 'prod']
|
|
18
|
-
if self.environment not in possible_environments:
|
|
19
|
-
raise ValueError(f"Environment should be in {','.join(possible_environments)}")
|
|
20
|
-
|
|
21
|
-
self.url = 'https://app.brynq-staging.com/api/v2/' if self.environment == 'dev' else 'https://app.brynq.com/api/v2/'
|
|
22
|
-
|
|
23
|
-
def _get_headers(self):
|
|
24
|
-
return {
|
|
25
|
-
'Authorization': f'Bearer {self.api_token}',
|
|
26
|
-
'Domain': self.subdomain
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
def _get_mappings(self, data_interface_id: int) -> dict:
|
|
30
|
-
"""
|
|
31
|
-
Get the mappings from the task in BrynQ
|
|
32
|
-
:param data_interface_id: The id of the data_interface in BrynQ. this does not have to be the task id of the current task
|
|
33
|
-
:return: A dictionary with the following structure: {mapping_title: {tuple(input): output}}
|
|
34
|
-
"""
|
|
35
|
-
response = requests.get(url=f'{self.url}interfaces/{data_interface_id}/data-mapping', headers=self._get_headers())
|
|
36
|
-
if response.status_code != 200:
|
|
37
|
-
raise ValueError(f'Error occurred while fetching mappings: {response.text}. Please always check if you have added BRYNQ_SUBDOMAIN to your .env file')
|
|
38
|
-
|
|
39
|
-
return response.json()
|
|
40
|
-
|
|
41
|
-
def get_mapping(self, data_interface_id: int, mapping: str, return_format: Literal['input_as_key', 'columns_names_as_keys', 'nested_input_output'] = 'input_as_key') -> dict:
|
|
42
|
-
"""
|
|
43
|
-
Get the mapping json from the mappings
|
|
44
|
-
:param data_interface_id: The id of the task in BrynQ. this does not have to be the task id of the current task
|
|
45
|
-
:param mapping: The name of the mapping
|
|
46
|
-
:param return_format: Determines how the mapping should be returned. Options are 'input_as_key' (Default, the input column is the key, the output columns are the values), 'columns_names_as_keys', 'nested_input_output'
|
|
47
|
-
:return: The json of the mapping
|
|
48
|
-
"""
|
|
49
|
-
# Find the mapping for the given sheet name
|
|
50
|
-
mappings = self._get_mappings(data_interface_id=data_interface_id)
|
|
51
|
-
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
52
|
-
if not mapping_data:
|
|
53
|
-
raise ValueError(f"Mapping named '{mapping}' not found")
|
|
54
|
-
|
|
55
|
-
# If the user want to get the column names back as keys, transform the data accordingly and return
|
|
56
|
-
if return_format == 'columns_names_as_keys':
|
|
57
|
-
final_mapping = []
|
|
58
|
-
for row in mapping_data['values']:
|
|
59
|
-
combined_dict = {}
|
|
60
|
-
combined_dict.update(row['input'])
|
|
61
|
-
combined_dict.update(row['output'])
|
|
62
|
-
final_mapping.append(combined_dict)
|
|
63
|
-
elif return_format == 'nested_input_output':
|
|
64
|
-
final_mapping = mapping_data
|
|
65
|
-
else:
|
|
66
|
-
final_mapping = {}
|
|
67
|
-
for value in mapping_data['values']:
|
|
68
|
-
input_values = []
|
|
69
|
-
output_values = []
|
|
70
|
-
for _, val in value['input'].items():
|
|
71
|
-
input_values.append(val)
|
|
72
|
-
for _, val in value['output'].items():
|
|
73
|
-
output_values.append(val)
|
|
74
|
-
# Detect if there are multiple input or output columns and concatenate them
|
|
75
|
-
if len(value['input'].items()) > 1 or len(value['output'].items()) > 1:
|
|
76
|
-
concatenated_input = ','.join(input_values)
|
|
77
|
-
concatenated_output = ','.join(output_values)
|
|
78
|
-
final_mapping[concatenated_input] = concatenated_output
|
|
79
|
-
else: # Default to assuming there's only one key-value pair if not concatenating
|
|
80
|
-
final_mapping[input_values[0]] = output_values[0]
|
|
81
|
-
return final_mapping
|
|
82
|
-
|
|
83
|
-
def get_mapping_as_dataframe(self, data_interface_id: int, mapping: str, prefix: bool = False):
|
|
84
|
-
"""
|
|
85
|
-
Get the mapping dataframe from the mappings
|
|
86
|
-
:param mapping: The name of the mapping
|
|
87
|
-
:param prefix: A boolean to indicate if the keys should be prefixed with 'input.' and 'output.'
|
|
88
|
-
:return: The dataframe of the mapping
|
|
89
|
-
"""
|
|
90
|
-
# Find the mapping for the given sheet name
|
|
91
|
-
mappings = self._get_mappings(data_interface_id=data_interface_id)
|
|
92
|
-
mapping_data = next((item for item in mappings if item['name'] == mapping), None)
|
|
93
|
-
if not mapping_data:
|
|
94
|
-
raise ValueError(f"Mapping named '{mapping}' not found")
|
|
95
|
-
|
|
96
|
-
# Extract the values which contain the input-output mappings
|
|
97
|
-
values = mapping_data['values']
|
|
98
|
-
|
|
99
|
-
# Create a list to hold all row data
|
|
100
|
-
rows = []
|
|
101
|
-
for value in values:
|
|
102
|
-
# Check if prefix is needed and adjust keys accordingly
|
|
103
|
-
if prefix:
|
|
104
|
-
input_data = {f'input.{key}': val for key, val in value['input'].items()}
|
|
105
|
-
output_data = {f'output.{key}': val for key, val in value['output'].items()}
|
|
106
|
-
else:
|
|
107
|
-
input_data = value['input']
|
|
108
|
-
output_data = value['output']
|
|
109
|
-
|
|
110
|
-
# Combine 'input' and 'output' dictionaries
|
|
111
|
-
row_data = {**input_data, **output_data}
|
|
112
|
-
rows.append(row_data)
|
|
113
|
-
|
|
114
|
-
# Create DataFrame from rows
|
|
115
|
-
df = pd.DataFrame(rows)
|
|
116
|
-
|
|
117
|
-
return df
|
|
118
|
-
|
|
119
|
-
def get_system_credential(self, system: str, label: Union[str, list], test_environment: bool = False) -> json:
|
|
120
|
-
"""
|
|
121
|
-
This method retrieves authentication credentials from BrynQ.
|
|
122
|
-
It returns the json data if the request does not return an error code
|
|
123
|
-
:param system: specifies which token is used. (lowercase)
|
|
124
|
-
:param label: reference to the used label
|
|
125
|
-
:param test_environment: boolean if the test environment is used
|
|
126
|
-
:return json response from BrynQ
|
|
127
|
-
"""
|
|
128
|
-
response = requests.get(url=f'{self.url}apps/{system}', headers=self._get_headers())
|
|
129
|
-
response.raise_for_status()
|
|
130
|
-
credentials = response.json()
|
|
131
|
-
# rename parameter for readability
|
|
132
|
-
if isinstance(label, str):
|
|
133
|
-
labels = [label]
|
|
134
|
-
else:
|
|
135
|
-
labels = label
|
|
136
|
-
# filter credentials based on label. All labels specified in label parameter should be present in the credential object
|
|
137
|
-
credentials = [credential for credential in credentials if all(label in credential['labels'] for label in labels)]
|
|
138
|
-
if system == 'profit':
|
|
139
|
-
credentials = [credential for credential in credentials if credential['isTestEnvironment'] is test_environment]
|
|
140
|
-
|
|
141
|
-
if len(credentials) == 0:
|
|
142
|
-
raise ValueError(f'No credentials found for {system}')
|
|
143
|
-
if len(credentials) != 1:
|
|
144
|
-
raise ValueError(f'Multiple credentials found for {system} with the specified labels')
|
|
145
|
-
|
|
146
|
-
return credentials[0]
|
|
147
|
-
|
|
148
|
-
def refresh_system_credential(self, system: str, system_id: int) -> json:
|
|
149
|
-
"""
|
|
150
|
-
This method refreshes Oauth authentication credentials in BrynQ.
|
|
151
|
-
It returns the json data if the request does not return an error code
|
|
152
|
-
:param system: specifies which token is used. (lowercase)
|
|
153
|
-
:param system_id: system id in BrynQ
|
|
154
|
-
:return json response from BrynQ
|
|
155
|
-
"""
|
|
156
|
-
response = requests.post(url=f'{self.url}apps/{system}/{system_id}/refresh', headers=self._get_headers())
|
|
157
|
-
response.raise_for_status()
|
|
158
|
-
credentials = response.json()
|
|
159
|
-
|
|
160
|
-
return credentials
|
|
161
|
-
|
|
162
|
-
def get_user_data(self):
|
|
163
|
-
"""
|
|
164
|
-
Get all users from BrynQ
|
|
165
|
-
:return: A list of users
|
|
166
|
-
"""
|
|
167
|
-
return requests.get(url=f'{self.url}users', headers=self._get_headers())
|
|
168
|
-
|
|
169
|
-
def get_user_authorization_qlik_app(self,dashboard_id):
|
|
170
|
-
"""
|
|
171
|
-
Get all users from BrynQ who have access to a qlik dashboard with their entities
|
|
172
|
-
:return: A list of users and entities
|
|
173
|
-
"""
|
|
174
|
-
return requests.get(url=f'{self.url}/qlik/{dashboard_id}/users', headers=self._get_headers())
|
|
175
|
-
|
|
176
|
-
def get_role_data(self):
|
|
177
|
-
"""
|
|
178
|
-
Get all roles from BrynQ
|
|
179
|
-
:return: A list of roles
|
|
180
|
-
"""
|
|
181
|
-
return requests.get(url=f'{self.url}roles', headers=self._get_headers())
|
|
182
|
-
|
|
183
|
-
def create_user(self, user_data: dict) -> requests.Response:
|
|
184
|
-
"""
|
|
185
|
-
Create a user in BrynQ
|
|
186
|
-
:param user_data: A dictionary with the following structure:
|
|
187
|
-
{
|
|
188
|
-
"name": "string",
|
|
189
|
-
"username": "string",
|
|
190
|
-
"email": "string",
|
|
191
|
-
"language": "string",
|
|
192
|
-
"salure_connect": bool,
|
|
193
|
-
"qlik_sense_analyzer": bool,
|
|
194
|
-
"qlik_sense_professional": bool
|
|
195
|
-
}
|
|
196
|
-
:return: A response object
|
|
197
|
-
"""
|
|
198
|
-
data = {
|
|
199
|
-
"name": user_data['name'],
|
|
200
|
-
"username": user_data['username'],
|
|
201
|
-
"email": user_data['email'],
|
|
202
|
-
"language": user_data['language'],
|
|
203
|
-
"products": {
|
|
204
|
-
"qlikSenseAnalyzer": user_data['qlik_sense_analyzer'],
|
|
205
|
-
"qlikSenseProfessional": user_data['qlik_sense_professional']
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return requests.post(url=f'{self.url}users', headers=self._get_headers(), json=data)
|
|
210
|
-
|
|
211
|
-
def update_user(self, user_id: str, user_data: dict) -> requests.Response:
|
|
212
|
-
"""
|
|
213
|
-
Update a user in BrynQ
|
|
214
|
-
:param user_id: The id of the user in BrynQ
|
|
215
|
-
:param user_data: A dictionary with the following structure:
|
|
216
|
-
{
|
|
217
|
-
"id": "string",
|
|
218
|
-
"name": "string",
|
|
219
|
-
"language": "string",
|
|
220
|
-
"salureconnect": bool,
|
|
221
|
-
"qlik sense analyser": bool,
|
|
222
|
-
"qlik sense professional": false
|
|
223
|
-
}
|
|
224
|
-
:return: A response object
|
|
225
|
-
"""
|
|
226
|
-
data = {
|
|
227
|
-
"name": user_data['name'],
|
|
228
|
-
"username": user_data['username'],
|
|
229
|
-
"email": user_data['email'],
|
|
230
|
-
"language": user_data['language'],
|
|
231
|
-
"products": {
|
|
232
|
-
"qlikSenseAnalyzer": user_data['qlik_sense_analyzer'],
|
|
233
|
-
"qlikSenseProfessional": user_data['qlik_sense_professional']
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return requests.put(url=f'{self.url}users/{user_id}', headers=self._get_headers(), json=data)
|
|
238
|
-
|
|
239
|
-
def delete_user(self, user_id: str) -> requests.Response:
|
|
240
|
-
"""
|
|
241
|
-
Delete a user in BrynQ
|
|
242
|
-
:param user_id: The id of the user in BrynQ
|
|
243
|
-
:return: A response object
|
|
244
|
-
"""
|
|
245
|
-
return requests.delete(url=f'{self.url}users/{user_id}', headers=self._get_headers())
|
|
246
|
-
|
|
247
|
-
def overwrite_user_roles(self, user_id: int, roles: list) -> requests.Response:
|
|
248
|
-
"""
|
|
249
|
-
Overwrite the roles of a user in BrynQ
|
|
250
|
-
:param user_id: The id of the user in BrynQ
|
|
251
|
-
:param roles: A list of role ids
|
|
252
|
-
:return: A response object
|
|
253
|
-
"""
|
|
254
|
-
data = {
|
|
255
|
-
"roles": roles
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
return requests.put(url=f'{self.url}users/{user_id}/roles', headers=self._get_headers(), json=data)
|
|
259
|
-
|
|
260
|
-
def get_source_system_entities(self, system: str) -> requests.Response:
|
|
261
|
-
"""
|
|
262
|
-
Get all entities from a source system in BrynQ
|
|
263
|
-
:param system: The name of the source system
|
|
264
|
-
:return: A response object
|
|
265
|
-
"""
|
|
266
|
-
return requests.get(url=f'{self.url}source-systems/{system}/entities', headers=self._get_headers())
|
|
267
|
-
|
|
268
|
-
def get_layers(self) -> requests.Response:
|
|
269
|
-
"""
|
|
270
|
-
Get all layers from a source system in BrynQ
|
|
271
|
-
:return: A response object
|
|
272
|
-
"""
|
|
273
|
-
return requests.get(url=f'{self.url}organization-chart/layers', headers=self._get_headers())
|
{brynq_sdk_brynq-1.1.0 → brynq_sdk_brynq-2.0.1}/brynq_sdk_brynq.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|