|
5 | 5 | from typing import TYPE_CHECKING, Optional, Union |
6 | 6 |
|
7 | 7 | import certifi |
8 | | -import requests |
9 | 8 | import urllib3 |
10 | 9 | from ape.types import AddressType, HexBytes, MessageSignature |
11 | 10 | from eth_utils import keccak |
12 | 11 | from requests.adapters import HTTPAdapter |
| 12 | +from requests_ratelimiter import LimiterSession |
13 | 13 |
|
14 | 14 | from ape_safe.client.types import ( |
15 | 15 | ExecutedTxData, |
|
24 | 24 |
|
25 | 25 | if TYPE_CHECKING: |
26 | 26 | from ape.api import AccountAPI |
27 | | - from requests import Response |
| 27 | + from requests import Response, Session |
28 | 28 |
|
29 | 29 | DEFAULT_HEADERS = { |
30 | 30 | "Accept": "application/json", |
|
33 | 33 |
|
34 | 34 |
|
35 | 35 | class BaseSafeClient(ABC): |
36 | | - def __init__(self, base_url: str): |
37 | | - self.base_url = base_url |
38 | | - |
39 | | - """Abstract methods""" |
| 36 | + """All custom SafeClient instances should implement this""" |
40 | 37 |
|
41 | 38 | @property |
42 | 39 | @abstractmethod |
@@ -135,11 +132,14 @@ def add_delegate(self, delegate: AddressType, label: str, delegator: "AccountAPI |
135 | 132 | @abstractmethod |
136 | 133 | def remove_delegate(self, delegate: AddressType, delegator: "AccountAPI"): ... |
137 | 134 |
|
138 | | - """Request methods""" |
| 135 | + |
| 136 | +class RequestsClient(BaseSafeClient): |
| 137 | + def __init__(self, base_url: str): |
| 138 | + self.base_url = base_url |
139 | 139 |
|
140 | 140 | @cached_property |
141 | | - def session(self) -> requests.Session: |
142 | | - session = requests.Session() |
| 141 | + def session(self) -> "Session": |
| 142 | + session = LimiterSession(per_second=5) |
143 | 143 | adapter = HTTPAdapter( |
144 | 144 | pool_connections=10, # Doing all the connections to the same url |
145 | 145 | pool_maxsize=100, # Number of concurrent connections |
|
0 commit comments