HedgeTech 0.0.0__py3-none-any.whl → 0.1.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.
- HedgeTech/Auth/__AuthAsyncClient.py +150 -0
- HedgeTech/Auth/__AuthSyncClient.py +153 -0
- HedgeTech/Auth/__init__.py +2 -0
- HedgeTech/DataEngine/__init__.py +4 -0
- HedgeTech/DataEngine/__tse_ifb/__AsyncClient.py +1588 -0
- HedgeTech/DataEngine/__tse_ifb/__SyncClient.py +1542 -0
- HedgeTech/DataEngine/__tse_ifb/__init__.py +2 -0
- HedgeTech/DataEngine/__tse_ifb/__io_types/__init__.py +39 -0
- HedgeTech/DataEngine/__tse_ifb/__io_types/__requests.py +47 -0
- HedgeTech/DataEngine/__tse_ifb/__io_types/__response.py +1921 -0
- {hedgetech-0.0.0.dist-info → hedgetech-0.1.0.dist-info}/METADATA +170 -8
- hedgetech-0.1.0.dist-info/RECORD +16 -0
- HedgeTech/__init__.py +0 -0
- hedgetech-0.0.0.dist-info/RECORD +0 -7
- {hedgetech-0.0.0.dist-info → hedgetech-0.1.0.dist-info}/WHEEL +0 -0
- {hedgetech-0.0.0.dist-info → hedgetech-0.1.0.dist-info}/licenses/LICENSE +0 -0
- {hedgetech-0.0.0.dist-info → hedgetech-0.1.0.dist-info}/licenses/NOTICE +0 -0
- {hedgetech-0.0.0.dist-info → hedgetech-0.1.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# ========================================|======================================== #
|
|
2
|
+
# Imports #
|
|
3
|
+
# ========================================|======================================== #
|
|
4
|
+
|
|
5
|
+
from httpx import (
|
|
6
|
+
AsyncClient ,
|
|
7
|
+
Timeout ,
|
|
8
|
+
)
|
|
9
|
+
from jwt import decode
|
|
10
|
+
|
|
11
|
+
# ========================================|======================================== #
|
|
12
|
+
# Class Definitions #
|
|
13
|
+
# ========================================|======================================== #
|
|
14
|
+
|
|
15
|
+
class AuthAsyncClient:
|
|
16
|
+
"""
|
|
17
|
+
Asynchronous client for interacting with the HedgeTech API using JWT-based authentication.
|
|
18
|
+
|
|
19
|
+
This class provides a high-level interface to authenticate users, manage JWT tokens,
|
|
20
|
+
and make authorized HTTP requests using an `httpx.AsyncClient`.
|
|
21
|
+
|
|
22
|
+
Attributes:
|
|
23
|
+
httpx_Client (AsyncClient): An instance of `httpx.AsyncClient` configured with authentication headers.
|
|
24
|
+
token (dict[str, str]): Dictionary containing authentication tokens, typically including 'Authorization'.
|
|
25
|
+
|
|
26
|
+
Example:
|
|
27
|
+
>>> client = await AuthAsyncClient.login(
|
|
28
|
+
... UserName_or_Email="user@example.com",
|
|
29
|
+
... Password="secure_password"
|
|
30
|
+
... )
|
|
31
|
+
>>> client.token['Authorization'][:10]
|
|
32
|
+
'eyJ0eXAiOi'
|
|
33
|
+
>>> client.Permissions # Decoded JWT payload
|
|
34
|
+
{'sub': 'user_id', 'exp': 1700350200, ...}
|
|
35
|
+
"""
|
|
36
|
+
|
|
37
|
+
def __init__(
|
|
38
|
+
self,
|
|
39
|
+
*,
|
|
40
|
+
httpx_Client:AsyncClient,
|
|
41
|
+
token:dict[str,str],
|
|
42
|
+
):
|
|
43
|
+
"""
|
|
44
|
+
Initialize the AuthAsyncClient with an existing httpx.AsyncClient and authentication token.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
httpx_Client (AsyncClient): Preconfigured AsyncClient for making authorized requests.
|
|
48
|
+
token (dict[str, str]): Dictionary containing authentication tokens.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
self.httpx_Client : AsyncClient = httpx_Client
|
|
52
|
+
self.token : dict[str,str] = token
|
|
53
|
+
|
|
54
|
+
self.UpdatePermission
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def UpdatePermission(self)-> None:
|
|
59
|
+
|
|
60
|
+
"""
|
|
61
|
+
Decodes the JWT 'Authorization' token to extract user permissions.
|
|
62
|
+
|
|
63
|
+
Raises:
|
|
64
|
+
ValueError: If the JWT cannot be decoded.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
try :
|
|
68
|
+
|
|
69
|
+
self.Permissions = decode(
|
|
70
|
+
jwt=self.token['Authorization'].encode(),
|
|
71
|
+
algorithms='HS256',
|
|
72
|
+
options={"verify_signature": False},
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
except Exception as e:
|
|
76
|
+
|
|
77
|
+
raise ValueError(e)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@classmethod
|
|
81
|
+
async def login(
|
|
82
|
+
cls,
|
|
83
|
+
*,
|
|
84
|
+
UserName_or_Email : str,
|
|
85
|
+
Password : str
|
|
86
|
+
)-> "AuthAsyncClient":
|
|
87
|
+
|
|
88
|
+
"""
|
|
89
|
+
Authenticate a user and return an instance of `AuthAsyncClient`.
|
|
90
|
+
|
|
91
|
+
This method performs the login request to the HedgeTech API, retrieves JWT tokens,
|
|
92
|
+
and configures an `httpx.AsyncClient` with authentication headers and cookies.
|
|
93
|
+
|
|
94
|
+
Args:
|
|
95
|
+
UserName_or_Email (str): The username or email of the user.
|
|
96
|
+
Password (str): The user's password.
|
|
97
|
+
|
|
98
|
+
Returns:
|
|
99
|
+
AuthAsyncClient: An initialized client ready to make authorized requests.
|
|
100
|
+
|
|
101
|
+
Raises:
|
|
102
|
+
ValueError: If the login attempt fails (e.g., wrong credentials).
|
|
103
|
+
|
|
104
|
+
Example:
|
|
105
|
+
>>> client = await AuthAsyncClient.login(
|
|
106
|
+
... UserName_or_Email="user@example.com",
|
|
107
|
+
... Password="secure_password"
|
|
108
|
+
... )
|
|
109
|
+
>>> client.token['Authorization'][:10]
|
|
110
|
+
'eyJ0eXAiOi'
|
|
111
|
+
"""
|
|
112
|
+
|
|
113
|
+
httpx_Client = AsyncClient(verify=True ,http1=False ,http2=True)
|
|
114
|
+
|
|
115
|
+
login_res = await httpx_Client.post(
|
|
116
|
+
url='https://core.hedgetech.ir/auth/user/token/issue',
|
|
117
|
+
data={
|
|
118
|
+
'UserName_or_Email' : UserName_or_Email,
|
|
119
|
+
'Password' : Password
|
|
120
|
+
}
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
if login_res.status_code == 201:
|
|
124
|
+
|
|
125
|
+
token = login_res.json()
|
|
126
|
+
headers = {'origin' : 'https://core.hedgetech.ir'}
|
|
127
|
+
headers.update(token)
|
|
128
|
+
|
|
129
|
+
httpx_Client = AsyncClient(
|
|
130
|
+
verify=True ,
|
|
131
|
+
http1=False ,
|
|
132
|
+
http2=True ,
|
|
133
|
+
headers=headers,
|
|
134
|
+
cookies=httpx_Client.cookies,
|
|
135
|
+
timeout=Timeout(
|
|
136
|
+
connect=.5,
|
|
137
|
+
read=1,
|
|
138
|
+
write=1,
|
|
139
|
+
pool=.5,
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
return cls(
|
|
144
|
+
httpx_Client = httpx_Client,
|
|
145
|
+
token = token
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
else :
|
|
149
|
+
|
|
150
|
+
raise ValueError(login_res.json().get('detail'))
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# ========================================|======================================== #
|
|
2
|
+
# Imports #
|
|
3
|
+
# ========================================|======================================== #
|
|
4
|
+
|
|
5
|
+
from httpx import (
|
|
6
|
+
Client ,
|
|
7
|
+
Timeout ,
|
|
8
|
+
)
|
|
9
|
+
from jwt import decode
|
|
10
|
+
|
|
11
|
+
# ========================================|======================================== #
|
|
12
|
+
# Class Definitions #
|
|
13
|
+
# ========================================|======================================== #
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AuthSyncClient:
|
|
17
|
+
"""
|
|
18
|
+
Synchronous client for interacting with the HedgeTech API using JWT-based authentication.
|
|
19
|
+
|
|
20
|
+
This class provides a high-level interface to authenticate users, manage JWT tokens,
|
|
21
|
+
and make authorized HTTP requests using an `httpx.Client`.
|
|
22
|
+
|
|
23
|
+
Attributes:
|
|
24
|
+
httpx_Client (Client): An instance of `httpx.Client` configured with authentication headers.
|
|
25
|
+
token (dict[str, str]): Dictionary containing authentication tokens, typically including 'Authorization'.
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
>>> client = AuthSyncClient.login(
|
|
29
|
+
... UserName_or_Email="user@example.com",
|
|
30
|
+
... Password="secure_password"
|
|
31
|
+
... )
|
|
32
|
+
>>> client.token['Authorization'][:10]
|
|
33
|
+
'eyJ0eXAiOi'
|
|
34
|
+
>>> client.Permissions # Decoded JWT payload
|
|
35
|
+
{'sub': 'user_id', 'exp': 1700350200, ...}
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
def __init__(
|
|
39
|
+
self,
|
|
40
|
+
*,
|
|
41
|
+
httpx_Client:Client,
|
|
42
|
+
token:dict[str,str],
|
|
43
|
+
):
|
|
44
|
+
"""
|
|
45
|
+
Initialize the AuthSyncClient with an existing httpx.Client and authentication token.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
httpx_Client (Client): Preconfigured Client for making authorized requests.
|
|
49
|
+
token (dict[str, str]): Dictionary containing authentication tokens.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
self.httpx_Client : Client = httpx_Client
|
|
53
|
+
self.token : dict[str,str] = token
|
|
54
|
+
|
|
55
|
+
self.UpdatePermission
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def UpdatePermission(self)-> None:
|
|
60
|
+
|
|
61
|
+
"""
|
|
62
|
+
Decodes the JWT 'Authorization' token to extract user permissions.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
ValueError: If the JWT cannot be decoded.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
try :
|
|
69
|
+
|
|
70
|
+
self.Permissions = decode(
|
|
71
|
+
jwt=self.token['Authorization'].encode(),
|
|
72
|
+
algorithms='HS256',
|
|
73
|
+
options={"verify_signature": False},
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
except Exception as e:
|
|
77
|
+
|
|
78
|
+
raise ValueError(e)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def login(
|
|
83
|
+
cls,
|
|
84
|
+
*,
|
|
85
|
+
UserName_or_Email : str,
|
|
86
|
+
Password : str
|
|
87
|
+
)-> "AuthSyncClient":
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
Authenticate a user synchronously and return an instance of `AuthSyncClient`.
|
|
91
|
+
|
|
92
|
+
This method performs the login request to the HedgeTech API, retrieves JWT tokens,
|
|
93
|
+
and configures an `httpx.Client` with authentication headers and cookies.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
UserName_or_Email (str): The username or email of the user.
|
|
97
|
+
Password (str): The user's password.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
AuthSyncClient: An initialized client ready to make authorized requests.
|
|
101
|
+
|
|
102
|
+
Raises:
|
|
103
|
+
ValueError: If the login attempt fails (e.g., wrong credentials).
|
|
104
|
+
|
|
105
|
+
Example:
|
|
106
|
+
>>> client = AuthSyncClient.login(
|
|
107
|
+
... UserName_or_Email="user@example.com",
|
|
108
|
+
... Password="secure_password"
|
|
109
|
+
... )
|
|
110
|
+
>>> client.token['Authorization'][:10]
|
|
111
|
+
'eyJ0eXAiOi'
|
|
112
|
+
"""
|
|
113
|
+
|
|
114
|
+
httpx_Client = Client(verify=True ,http1=False ,http2=True)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
login_res = httpx_Client.post(
|
|
118
|
+
url='https://core.hedgetech.ir/auth/user/token/issue',
|
|
119
|
+
data={
|
|
120
|
+
'UserName_or_Email' : UserName_or_Email,
|
|
121
|
+
'Password' : Password
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if login_res.status_code == 201:
|
|
127
|
+
|
|
128
|
+
token = login_res.json()
|
|
129
|
+
headers = {'origin' : 'https://core.hedgetech.ir'}
|
|
130
|
+
headers.update(token)
|
|
131
|
+
|
|
132
|
+
httpx_Client = Client(
|
|
133
|
+
verify=True ,
|
|
134
|
+
http1=False ,
|
|
135
|
+
http2=True ,
|
|
136
|
+
headers=headers,
|
|
137
|
+
cookies=httpx_Client.cookies,
|
|
138
|
+
timeout=Timeout(
|
|
139
|
+
connect=.5,
|
|
140
|
+
read=1,
|
|
141
|
+
write=1,
|
|
142
|
+
pool=.5,
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
return cls(
|
|
147
|
+
httpx_Client = httpx_Client,
|
|
148
|
+
token = login_res.json()
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
else :
|
|
152
|
+
|
|
153
|
+
raise ValueError(login_res.json().get('detail'))
|