tonutils 0.5.5__py3-none-any.whl → 0.5.6__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.
- tonutils/client/_base.py +23 -5
- tonutils/client/quicknode.py +13 -1
- tonutils/client/tatum.py +8 -0
- tonutils/client/tonapi.py +7 -0
- tonutils/client/toncenter.py +13 -0
- {tonutils-0.5.5.dist-info → tonutils-0.5.6.dist-info}/METADATA +1 -1
- {tonutils-0.5.5.dist-info → tonutils-0.5.6.dist-info}/RECORD +10 -10
- {tonutils-0.5.5.dist-info → tonutils-0.5.6.dist-info}/WHEEL +0 -0
- {tonutils-0.5.5.dist-info → tonutils-0.5.6.dist-info}/licenses/LICENSE +0 -0
- {tonutils-0.5.5.dist-info → tonutils-0.5.6.dist-info}/top_level.txt +0 -0
tonutils/client/_base.py
CHANGED
|
@@ -3,7 +3,8 @@ from __future__ import annotations
|
|
|
3
3
|
import asyncio
|
|
4
4
|
import json
|
|
5
5
|
import random
|
|
6
|
-
from typing import Any, Optional, List, Dict, Union
|
|
6
|
+
from typing import Any, Optional, List, Dict, Union, AsyncGenerator
|
|
7
|
+
from contextlib import asynccontextmanager
|
|
7
8
|
|
|
8
9
|
import aiohttp
|
|
9
10
|
from aiolimiter import AsyncLimiter
|
|
@@ -27,6 +28,7 @@ class Client:
|
|
|
27
28
|
self.rps = kwargs.get("rps", 1)
|
|
28
29
|
self.max_retries = kwargs.get("max_retries", 0)
|
|
29
30
|
|
|
31
|
+
self._session: aiohttp.ClientSession = kwargs.get("session", None)
|
|
30
32
|
self._limiter = AsyncLimiter(
|
|
31
33
|
max_rate=self.rps,
|
|
32
34
|
time_period=1,
|
|
@@ -86,6 +88,24 @@ class Client:
|
|
|
86
88
|
seconds = retry_after + random.uniform(0.2, 0.5)
|
|
87
89
|
await asyncio.sleep(seconds)
|
|
88
90
|
|
|
91
|
+
@asynccontextmanager
|
|
92
|
+
async def _get_session(self) -> AsyncGenerator[aiohttp.ClientSession, None]:
|
|
93
|
+
if self._session:
|
|
94
|
+
yield self._session
|
|
95
|
+
else:
|
|
96
|
+
async with aiohttp.ClientSession(
|
|
97
|
+
timeout=aiohttp.ClientTimeout(total=self.timeout)
|
|
98
|
+
) as session:
|
|
99
|
+
yield session
|
|
100
|
+
|
|
101
|
+
async def close_session(self) -> None:
|
|
102
|
+
"""
|
|
103
|
+
Close the aiohttp session if it was created by the client.
|
|
104
|
+
"""
|
|
105
|
+
if self._session:
|
|
106
|
+
await self._session.close()
|
|
107
|
+
self._session = None
|
|
108
|
+
|
|
89
109
|
async def _request(
|
|
90
110
|
self,
|
|
91
111
|
method: str,
|
|
@@ -114,14 +134,12 @@ class Client:
|
|
|
114
134
|
await self._limiter.acquire()
|
|
115
135
|
|
|
116
136
|
try:
|
|
117
|
-
async with
|
|
118
|
-
headers=self.headers,
|
|
119
|
-
timeout=aiohttp.ClientTimeout(total=self.timeout)
|
|
120
|
-
) as session:
|
|
137
|
+
async with self._get_session() as session:
|
|
121
138
|
async with session.request(
|
|
122
139
|
method=method,
|
|
123
140
|
url=url,
|
|
124
141
|
params=params,
|
|
142
|
+
headers=self.headers,
|
|
125
143
|
json=body,
|
|
126
144
|
) as response:
|
|
127
145
|
content = await self._parse_response(response)
|
tonutils/client/quicknode.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
|
|
3
|
+
from aiohttp import ClientSession
|
|
4
|
+
|
|
3
5
|
from .toncenter import ToncenterV2Client
|
|
4
6
|
|
|
5
7
|
|
|
@@ -17,6 +19,8 @@ class QuicknodeClient(ToncenterV2Client):
|
|
|
17
19
|
http_provider_url: str,
|
|
18
20
|
rps: Optional[int] = None,
|
|
19
21
|
max_retries: int = 1,
|
|
22
|
+
timeout: Optional[int] = 10,
|
|
23
|
+
session: Optional[ClientSession] = None,
|
|
20
24
|
) -> None:
|
|
21
25
|
"""
|
|
22
26
|
Initialize the QuicknodeClient.
|
|
@@ -25,9 +29,17 @@ class QuicknodeClient(ToncenterV2Client):
|
|
|
25
29
|
You can obtain one at: https://quicknode.com
|
|
26
30
|
:param rps: Optional requests per second (RPS) limit.
|
|
27
31
|
:param max_retries: Number of retries for rate-limited requests. Defaults to 1.
|
|
32
|
+
:param timeout: Response timeout in seconds. Not used if session is specified. Defaults to 10.
|
|
33
|
+
:param session: Aiohttp session to avoid creating new ones every time. By default, a new one is created for each request. If specified, remember to call session_close when finished.
|
|
28
34
|
"""
|
|
29
35
|
if not http_provider_url:
|
|
30
36
|
raise ValueError("`http_provider_url` is required to initialize QuicknodeClient")
|
|
31
37
|
|
|
32
38
|
base_url = http_provider_url.rstrip("/") + self.API_VERSION_PATH
|
|
33
|
-
super().__init__(
|
|
39
|
+
super().__init__(
|
|
40
|
+
base_url=base_url,
|
|
41
|
+
rps=rps,
|
|
42
|
+
max_retries=max_retries,
|
|
43
|
+
timeout=timeout,
|
|
44
|
+
session=session,
|
|
45
|
+
)
|
tonutils/client/tatum.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from typing import Optional
|
|
2
2
|
|
|
3
|
+
from aiohttp import ClientSession
|
|
4
|
+
|
|
3
5
|
from .toncenter import ToncenterV2Client
|
|
4
6
|
|
|
5
7
|
|
|
@@ -20,6 +22,8 @@ class TatumClient(ToncenterV2Client):
|
|
|
20
22
|
base_url: Optional[str] = None,
|
|
21
23
|
rps: Optional[int] = None,
|
|
22
24
|
max_retries: int = 1,
|
|
25
|
+
timeout: Optional[int] = 10,
|
|
26
|
+
session: Optional[ClientSession] = None,
|
|
23
27
|
) -> None:
|
|
24
28
|
"""
|
|
25
29
|
Initialize the TatumClient.
|
|
@@ -30,6 +34,8 @@ class TatumClient(ToncenterV2Client):
|
|
|
30
34
|
:param base_url: Optional custom base URL. Defaults to Tatum's public gateway.
|
|
31
35
|
:param rps: Optional requests per second (RPS) limit.
|
|
32
36
|
:param max_retries: Number of retries for rate-limited requests. Defaults to 1.
|
|
37
|
+
:param timeout: Response timeout in seconds. Not used if session is specified. Defaults to 10.
|
|
38
|
+
:param session: Aiohttp session to avoid creating new ones every time. By default, a new one is created for each request. If specified, remember to call session_close when finished.
|
|
33
39
|
"""
|
|
34
40
|
if not api_key:
|
|
35
41
|
raise ValueError("`api_key` is required to initialize TatumClient.")
|
|
@@ -47,4 +53,6 @@ class TatumClient(ToncenterV2Client):
|
|
|
47
53
|
is_testnet=is_testnet,
|
|
48
54
|
rps=rps,
|
|
49
55
|
max_retries=max_retries,
|
|
56
|
+
timeout=timeout,
|
|
57
|
+
session=session,
|
|
50
58
|
)
|
tonutils/client/tonapi.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
from typing import Any, Dict, List, Optional, Union
|
|
2
2
|
|
|
3
3
|
from pytoniq_core import Address, Builder, Cell, HashMap, Transaction, Slice
|
|
4
|
+
from aiohttp import ClientSession
|
|
4
5
|
|
|
5
6
|
from ._base import Client
|
|
6
7
|
from .utils import RunGetMethodStack, RunGetMethodResult, unpack_config
|
|
@@ -24,6 +25,8 @@ class TonapiClient(Client):
|
|
|
24
25
|
base_url: Optional[str] = None,
|
|
25
26
|
rps: Optional[int] = None,
|
|
26
27
|
max_retries: int = 1,
|
|
28
|
+
timeout: Optional[int] = 10,
|
|
29
|
+
session: Optional[ClientSession] = None,
|
|
27
30
|
) -> None:
|
|
28
31
|
"""
|
|
29
32
|
Initialize the TonapiClient.
|
|
@@ -33,6 +36,8 @@ class TonapiClient(Client):
|
|
|
33
36
|
:param base_url: Optional custom base URL. If not provided, uses the official endpoint.
|
|
34
37
|
:param rps: Optional requests per second (RPS) limit.
|
|
35
38
|
:param max_retries: Number of retries for rate-limited requests. Defaults to 1.
|
|
39
|
+
:param timeout: Response timeout in seconds. Not used if session is specified. Defaults to 10.
|
|
40
|
+
:param session: Aiohttp session to avoid creating new ones every time. By default, a new one is created for each request. If specified, remember to call session_close when finished.
|
|
36
41
|
"""
|
|
37
42
|
if not api_key:
|
|
38
43
|
raise ValueError("`api_key` is required to initialize TonapiClient.")
|
|
@@ -47,6 +52,8 @@ class TonapiClient(Client):
|
|
|
47
52
|
is_testnet=is_testnet,
|
|
48
53
|
rps=rps,
|
|
49
54
|
max_retries=max_retries,
|
|
55
|
+
timeout=timeout,
|
|
56
|
+
session=session,
|
|
50
57
|
)
|
|
51
58
|
|
|
52
59
|
async def run_get_method(
|
tonutils/client/toncenter.py
CHANGED
|
@@ -2,6 +2,7 @@ import base64
|
|
|
2
2
|
from typing import Any, Dict, List, Optional, Union
|
|
3
3
|
|
|
4
4
|
from pytoniq_core import Address, Builder, Cell, HashMap, Transaction, Slice
|
|
5
|
+
from aiohttp import ClientSession
|
|
5
6
|
|
|
6
7
|
from ._base import Client
|
|
7
8
|
from .utils import RunGetMethodStack, RunGetMethodResult, unpack_config
|
|
@@ -26,6 +27,8 @@ class ToncenterV2Client(Client):
|
|
|
26
27
|
base_url: Optional[str] = None,
|
|
27
28
|
rps: Optional[int] = None,
|
|
28
29
|
max_retries: int = 1,
|
|
30
|
+
timeout: Optional[int] = 10,
|
|
31
|
+
session: Optional[ClientSession] = None,
|
|
29
32
|
) -> None:
|
|
30
33
|
"""
|
|
31
34
|
Initialize the ToncenterV2Client.
|
|
@@ -37,6 +40,8 @@ class ToncenterV2Client(Client):
|
|
|
37
40
|
If not set, defaults to the official Toncenter URLs.
|
|
38
41
|
:param rps: Optional requests per second (RPS) limit.
|
|
39
42
|
:param max_retries: Number of retries for rate-limited requests. Defaults to 1.
|
|
43
|
+
:param timeout: Response timeout in seconds. Not used if session is specified. Defaults to 10.
|
|
44
|
+
:param session: Aiohttp session to avoid creating new ones every time. By default, a new one is created for each request. If specified, remember to call session_close when finished.
|
|
40
45
|
"""
|
|
41
46
|
default_url = "https://testnet.toncenter.com" if is_testnet else "https://toncenter.com"
|
|
42
47
|
base_url = (base_url or default_url).rstrip("/") + self.API_VERSION_PATH
|
|
@@ -48,6 +53,8 @@ class ToncenterV2Client(Client):
|
|
|
48
53
|
is_testnet=is_testnet,
|
|
49
54
|
rps=rps,
|
|
50
55
|
max_retries=max_retries,
|
|
56
|
+
timeout=timeout,
|
|
57
|
+
session=session,
|
|
51
58
|
)
|
|
52
59
|
|
|
53
60
|
async def run_get_method(
|
|
@@ -178,6 +185,8 @@ class ToncenterV3Client(Client):
|
|
|
178
185
|
base_url: Optional[str] = None,
|
|
179
186
|
rps: Optional[int] = None,
|
|
180
187
|
max_retries: int = 1,
|
|
188
|
+
timeout: Optional[int] = 10,
|
|
189
|
+
session: Optional[ClientSession] = None,
|
|
181
190
|
) -> None:
|
|
182
191
|
"""
|
|
183
192
|
Initialize the ToncenterV3Client.
|
|
@@ -189,6 +198,8 @@ class ToncenterV3Client(Client):
|
|
|
189
198
|
Defaults to official Toncenter endpoints.
|
|
190
199
|
:param rps: Optional requests per second (RPS) limit.
|
|
191
200
|
:param max_retries: Number of retries for rate-limited requests. Defaults to 1.
|
|
201
|
+
:param timeout: Response timeout in seconds. Not used if session is specified. Defaults to 10.
|
|
202
|
+
:param session: Aiohttp session to avoid creating new ones every time. By default, a new one is created for each request. If specified, remember to call session_close when finished.
|
|
192
203
|
"""
|
|
193
204
|
default_url = (
|
|
194
205
|
"https://testnet.toncenter.com"
|
|
@@ -204,6 +215,8 @@ class ToncenterV3Client(Client):
|
|
|
204
215
|
is_testnet=is_testnet,
|
|
205
216
|
rps=rps,
|
|
206
217
|
max_retries=max_retries,
|
|
218
|
+
timeout=timeout,
|
|
219
|
+
session=session,
|
|
207
220
|
)
|
|
208
221
|
|
|
209
222
|
async def run_get_method(
|
|
@@ -6,12 +6,12 @@ tonutils/exceptions.py,sha256=FCgD7mr4K5KDv7ZLkQmy2CseMSqi1S4UzOQuLybNkSk,1351
|
|
|
6
6
|
tonutils/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
tonutils/utils.py,sha256=ZsIDGIDCzoH34qv79uSE3KH_Gqa2nYxD1csalVJX90I,8679
|
|
8
8
|
tonutils/client/__init__.py,sha256=-MmgreKvoHTywzzBKFNbuX4wOJrwiFfKz2kE38_FeK8,404
|
|
9
|
-
tonutils/client/_base.py,sha256=
|
|
9
|
+
tonutils/client/_base.py,sha256=W4IQof61jWyRBL-_Fim9TWACHqhr0LdJ3Uw_y-ImRGs,10552
|
|
10
10
|
tonutils/client/lite.py,sha256=iLgVSUWwDNrMwRFOP1VUq8iMItvV4g-PI9n0wfVQQK4,5853
|
|
11
|
-
tonutils/client/quicknode.py,sha256=
|
|
12
|
-
tonutils/client/tatum.py,sha256=
|
|
13
|
-
tonutils/client/tonapi.py,sha256=
|
|
14
|
-
tonutils/client/toncenter.py,sha256=
|
|
11
|
+
tonutils/client/quicknode.py,sha256=HfeZwhdjYx2ob6T2EJT8dgfLR2bm67q2BZSS4ZSh5Sg,1674
|
|
12
|
+
tonutils/client/tatum.py,sha256=cLCj_DUaL8butSWfuCGT47f4rD6B4stYQVX_3vBJNOE,2156
|
|
13
|
+
tonutils/client/tonapi.py,sha256=g8eabxEY3cYoG4Sr1TqvTmOxwtx0prXggAK9NiPkYOg,5714
|
|
14
|
+
tonutils/client/toncenter.py,sha256=LPuBmtqGpvzRKmIeC6vBNXh4-2-X_8sa4VUcZ073y9Q,11330
|
|
15
15
|
tonutils/client/utils.py,sha256=ouzzS_r0YYHplmzoE9-2seLhtjU7O32FLGwSIgIoo3k,7339
|
|
16
16
|
tonutils/dns/__init__.py,sha256=zEOmml_INEoBfr3h5S1PHvr1Wksr_9Owf8S3gLWDHWI,52
|
|
17
17
|
tonutils/dns/categories.py,sha256=1rWN1LmuHt0rmPOf0EJDNMeYkmnKR4nYCPNwLJf2dvc,281
|
|
@@ -125,8 +125,8 @@ tonutils/wallet/contract/v2.py,sha256=SWik7CtQzNjcyjNc2G_hu8xPYun28GC_Ky0Sky0jX5
|
|
|
125
125
|
tonutils/wallet/contract/v3.py,sha256=0mTWsZqTom1dWsKtjcUjyjt7Z7f0pExdDxeQi0lbk_Y,3107
|
|
126
126
|
tonutils/wallet/contract/v4.py,sha256=LfCujQUNy_ScBfTqgSWsr6cRs_IGXkq2pxAML0Qvsz4,6347
|
|
127
127
|
tonutils/wallet/contract/v5.py,sha256=uiLVI_tAI-69__MUeZZFKzNo3GRuoNqKdQRUbZ1NL20,8355
|
|
128
|
-
tonutils-0.5.
|
|
129
|
-
tonutils-0.5.
|
|
130
|
-
tonutils-0.5.
|
|
131
|
-
tonutils-0.5.
|
|
132
|
-
tonutils-0.5.
|
|
128
|
+
tonutils-0.5.6.dist-info/licenses/LICENSE,sha256=fr0RzMsygzM2gNKLyH8NdrwYGFC4RCMhqMrtICms5mM,1060
|
|
129
|
+
tonutils-0.5.6.dist-info/METADATA,sha256=-RyJGfXBs9lLMN_QLhmGIKfCY8vDkqDLdr27xiSfd-0,4552
|
|
130
|
+
tonutils-0.5.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
131
|
+
tonutils-0.5.6.dist-info/top_level.txt,sha256=-7H_mGl8S9HKQrkUiTLmEbtMM-knzRzd_a0cZZnuZIU,9
|
|
132
|
+
tonutils-0.5.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|