brynq-sdk-dynamics 1.0.0__py3-none-any.whl
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .dynamics import Dynamics
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import requests
|
|
2
|
+
import pandas as pd
|
|
3
|
+
from brynq_sdk_brynq import BrynQ
|
|
4
|
+
from typing import Optional, Literal, Dict, Any
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Dynamics(BrynQ):
|
|
8
|
+
def __init__(self, system_type: Optional[Literal['source', 'target']] = None, debug=False) -> None:
|
|
9
|
+
"""
|
|
10
|
+
Initializes the Dynamics client, retrieves credentials, and sets authorization headers.
|
|
11
|
+
|
|
12
|
+
"""
|
|
13
|
+
super().__init__()
|
|
14
|
+
credentials = self.interfaces.credentials.get(system="dynamics-365", system_type=system_type)
|
|
15
|
+
credentials = credentials.get('data')
|
|
16
|
+
self.client_id = credentials['client_id']
|
|
17
|
+
self.client_secret = credentials['client_secret']
|
|
18
|
+
self.resource = credentials['resource']
|
|
19
|
+
self.tenant = credentials['tenant_id']
|
|
20
|
+
self.headers = {'authorization': f'Bearer {self.get_access_token()}'}
|
|
21
|
+
self.timeout = 3600
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def get_access_token(self) -> str:
|
|
25
|
+
"""
|
|
26
|
+
Retrieves an OAuth2 access token from Microsoft Azure AD.
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
url = f"https://login.microsoftonline.com/{self.tenant}/oauth2/token"
|
|
30
|
+
payload = {'grant_type': 'client_credentials',
|
|
31
|
+
'client_id': self.client_id,
|
|
32
|
+
'client_secret': self.client_secret,
|
|
33
|
+
'resource': self.resource}
|
|
34
|
+
response = requests.post(url= url, data=payload, timeout=self.timeout)
|
|
35
|
+
return response.json()['access_token']
|
|
36
|
+
|
|
37
|
+
def get_data(self, endpoint: str, params: Optional[Dict[str, Any]] = None) -> pd.DataFrame:
|
|
38
|
+
"""
|
|
39
|
+
Retrieves data from a specified Dynamics 365 OData endpoint.
|
|
40
|
+
|
|
41
|
+
Handles pagination using '@odata.nextLink' and combines results into a single pandas DataFrame.
|
|
42
|
+
|
|
43
|
+
"""
|
|
44
|
+
url = f"{self.resource}/data/{endpoint}"
|
|
45
|
+
df = pd.DataFrame()
|
|
46
|
+
|
|
47
|
+
while True:
|
|
48
|
+
response = requests.get(url, headers=self.headers, params=params, timeout=self.timeout)
|
|
49
|
+
df = pd.concat([df, pd.DataFrame(response.json()['value'])], ignore_index=True)
|
|
50
|
+
|
|
51
|
+
if '@odata.nextLink' in response.json():
|
|
52
|
+
url = response.json()['@odata.nextLink']
|
|
53
|
+
params = None
|
|
54
|
+
else:
|
|
55
|
+
break
|
|
56
|
+
|
|
57
|
+
return df
|
|
58
|
+
|
|
59
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: brynq_sdk_dynamics
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Dynamics wrapper from BrynQ
|
|
5
|
+
Author: BrynQ
|
|
6
|
+
Author-email: support@brynq.com
|
|
7
|
+
License: BrynQ License
|
|
8
|
+
Requires-Dist: brynq-sdk-brynq<5,>=4
|
|
9
|
+
Dynamic: author
|
|
10
|
+
Dynamic: author-email
|
|
11
|
+
Dynamic: description
|
|
12
|
+
Dynamic: license
|
|
13
|
+
Dynamic: requires-dist
|
|
14
|
+
Dynamic: summary
|
|
15
|
+
|
|
16
|
+
Dynamics365 wrapper from BrynQ
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
brynq_sdk_dynamics/__init__.py,sha256=qAseG7VmlPEkN3KvZKkeWT8gSaSbKu8Gbzzv53E0u70,30
|
|
2
|
+
brynq_sdk_dynamics/dynamics.py,sha256=u_gnrLniP2XfZhOaBdUB3P88P_JhBRLIbp20ER5ZcJs,2181
|
|
3
|
+
brynq_sdk_dynamics-1.0.0.dist-info/METADATA,sha256=4AgC1a3ww7fYek7N4opai36ma4XAAz4533ITaNt905M,353
|
|
4
|
+
brynq_sdk_dynamics-1.0.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
5
|
+
brynq_sdk_dynamics-1.0.0.dist-info/top_level.txt,sha256=5i0LT1IMQ1k4_bCFZOcGazSlFHmUQRZDmAyUrPwFdvU,19
|
|
6
|
+
brynq_sdk_dynamics-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
brynq_sdk_dynamics
|