brynq-sdk-dynamics 1.0.0__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.
@@ -0,0 +1,10 @@
1
+ Metadata-Version: 1.0
2
+ Name: brynq_sdk_dynamics
3
+ Version: 1.0.0
4
+ Summary: Dynamics wrapper from BrynQ
5
+ Home-page: UNKNOWN
6
+ Author: BrynQ
7
+ Author-email: support@brynq.com
8
+ License: BrynQ License
9
+ Description: Dynamics365 wrapper from BrynQ
10
+ Platform: UNKNOWN
@@ -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,10 @@
1
+ Metadata-Version: 1.0
2
+ Name: brynq-sdk-dynamics
3
+ Version: 1.0.0
4
+ Summary: Dynamics wrapper from BrynQ
5
+ Home-page: UNKNOWN
6
+ Author: BrynQ
7
+ Author-email: support@brynq.com
8
+ License: BrynQ License
9
+ Description: Dynamics365 wrapper from BrynQ
10
+ Platform: UNKNOWN
@@ -0,0 +1,9 @@
1
+ setup.py
2
+ brynq_sdk_dynamics/__init__.py
3
+ brynq_sdk_dynamics/dynamics.py
4
+ brynq_sdk_dynamics.egg-info/PKG-INFO
5
+ brynq_sdk_dynamics.egg-info/SOURCES.txt
6
+ brynq_sdk_dynamics.egg-info/dependency_links.txt
7
+ brynq_sdk_dynamics.egg-info/not-zip-safe
8
+ brynq_sdk_dynamics.egg-info/requires.txt
9
+ brynq_sdk_dynamics.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ brynq-sdk-brynq<5,>=4
@@ -0,0 +1 @@
1
+ brynq_sdk_dynamics
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,16 @@
1
+ from setuptools import setup, find_namespace_packages
2
+
3
+ setup(
4
+ name='brynq_sdk_dynamics',
5
+ version='1.0.0',
6
+ description='Dynamics wrapper from BrynQ',
7
+ long_description='Dynamics365 wrapper from BrynQ',
8
+ author='BrynQ',
9
+ author_email='support@brynq.com',
10
+ packages=find_namespace_packages(include=['brynq_sdk*']),
11
+ license='BrynQ License',
12
+ install_requires=[
13
+ 'brynq-sdk-brynq>=4,<5',
14
+ ],
15
+ zip_safe=False,
16
+ )