marzban 0.2.7__py3-none-any.whl → 0.2.9__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.
marzban/__init__.py CHANGED
@@ -25,7 +25,9 @@ from .models import (
25
25
  ProxyInbound,
26
26
  Token,
27
27
  HTTPValidationError,
28
- ValidationError
28
+ ValidationError,
29
+ SubscriptionUserResponse,
30
+ SystemStats
29
31
  )
30
32
 
31
33
  __all__ = (
@@ -57,6 +59,8 @@ __all__ = (
57
59
  "Token",
58
60
  "HTTPValidationError",
59
61
  "ValidationError",
62
+ "SubscriptionUserResponse",
63
+ "SystemStats"
60
64
  )
61
65
 
62
- __version__ = "0.2.7"
66
+ __version__ = "0.2.9"
marzban/api.py CHANGED
@@ -4,9 +4,9 @@ from pydantic import BaseModel
4
4
  from .models import *
5
5
 
6
6
  class MarzbanAPI:
7
- def __init__(self, base_url: str):
7
+ def __init__(self, base_url: str, *, timeout: float = 10.0, verify: bool = False):
8
8
  self.base_url = base_url
9
- self.client = httpx.AsyncClient(base_url=base_url)
9
+ self.client = httpx.AsyncClient(base_url=base_url, verify=verify, timeout=timeout)
10
10
 
11
11
  def _get_headers(self, token: str) -> Dict[str, str]:
12
12
  return {"Authorization": f"Bearer {token}"}
@@ -223,5 +223,45 @@ class MarzbanAPI:
223
223
  response = await self._request("GET", url, token, params=params)
224
224
  return NodesUsageResponse(**response.json())
225
225
 
226
+ async def get_user_subscription_info(self, url: str = None, token: str = None) -> SubscriptionUserResponse:
227
+ if url:
228
+ # Use the provided URL if it is given
229
+ final_url = url + "/info"
230
+ elif token:
231
+ # Form the URL using the token if it is provided
232
+ final_url = f"/sub/{token}/info"
233
+ else:
234
+ raise ValueError("Either url or token must be provided")
235
+
236
+ response = await self._request("GET", final_url)
237
+ return SubscriptionUserResponse(**response.json())
238
+
239
+ async def get_user_usage(self, url: str = None, token: str = None, start: Optional[str] = None, end: Optional[str] = None) -> Any:
240
+ if url:
241
+ # Use the provided URL if it is given
242
+ final_url = url + "/usage"
243
+ elif token:
244
+ # Form the URL using the token if it is provided
245
+ final_url = f"/sub/{token}/usage"
246
+ else:
247
+ raise ValueError("Either url or token must be provided")
248
+
249
+ params = {"start": start, "end": end}
250
+ response = await self._request("GET", final_url, params=params)
251
+ return response.json()
252
+
253
+ async def get_user_subscription_with_client_type(self, client_type: str, url: str = None, token: str = None) -> Any:
254
+ if url:
255
+ # Use the provided URL if it is given
256
+ final_url = url + f"/{client_type}"
257
+ elif token:
258
+ # Form the URL using the token if it is provided
259
+ final_url = f"/sub/{token}/{client_type}"
260
+ else:
261
+ raise ValueError("Either url or token must be provided")
262
+
263
+ response = await self._request("GET", final_url)
264
+ return response.json()
265
+
226
266
  async def close(self):
227
267
  await self.client.aclose()
marzban/models.py CHANGED
@@ -1,5 +1,5 @@
1
- from pydantic import BaseModel
2
- from typing import Optional, List, Dict, Any, ClassVar
1
+ from pydantic import BaseModel, field_validator, ValidationInfo, AfterValidator, ValidationError
2
+ from typing import Optional, List, Dict, Any, ClassVar, Annotated
3
3
 
4
4
  class Token(BaseModel):
5
5
  access_token: str
@@ -23,19 +23,6 @@ class AdminModify(BaseModel):
23
23
  class HTTPValidationError(BaseModel):
24
24
  detail: Optional[List[Dict[str, Any]]] = None
25
25
 
26
- class SystemStats(BaseModel):
27
- version: str
28
- mem_total: int
29
- mem_used: int
30
- cpu_cores: int
31
- cpu_usage: float
32
- total_user: int
33
- users_active: int
34
- incoming_bandwidth: int
35
- outgoing_bandwidth: int
36
- incoming_bandwidth_speed: int
37
- outgoing_bandwidth_speed: int
38
-
39
26
  class ProxySettings(BaseModel):
40
27
  id: Optional[str] = None
41
28
  flow: Optional[str] = None
@@ -69,12 +56,19 @@ class UserResponse(BaseModel):
69
56
  on_hold_expire_duration: Optional[int] = None
70
57
  on_hold_timeout: Optional[str] = None
71
58
  status: Optional[str] = None
59
+ admin: Optional[Admin] = None
72
60
  used_traffic: Optional[int] = None
73
61
  lifetime_used_traffic: Optional[int] = None
74
62
  created_at: Optional[str] = None
75
63
  links: Optional[List[str]] = []
76
64
  subscription_url: Optional[str] = None
65
+ subscription_token: Optional[str] = None
77
66
  excluded_inbounds: Optional[Dict[str, List[str]]] = None
67
+
68
+ def __init__(self, **data):
69
+ super().__init__(**data)
70
+ if not self.subscription_token and self.subscription_url:
71
+ self.subscription_token = self.subscription_url.split('/')[-1]
78
72
 
79
73
  class NodeCreate(BaseModel):
80
74
  name: str
@@ -195,4 +189,40 @@ class UserStatus(BaseModel):
195
189
  class ValidationError(BaseModel):
196
190
  loc: List[Any]
197
191
  msg: str
198
- type: str
192
+ type: str
193
+
194
+ class SubscriptionUserResponse(BaseModel):
195
+ proxies: Dict[str, Any]
196
+ expire: Optional[int] = None
197
+ data_limit: Optional[int] = None
198
+ data_limit_reset_strategy: str = "no_reset"
199
+ inbounds: Dict[str, List[str]] = {}
200
+ note: Optional[str] = None
201
+ sub_updated_at: Optional[str] = None
202
+ sub_last_user_agent: Optional[str] = None
203
+ online_at: Optional[str] = None
204
+ on_hold_expire_duration: Optional[int] = None
205
+ on_hold_timeout: Optional[str] = None
206
+ auto_delete_in_days: Optional[int] = None
207
+ username: str
208
+ status: str
209
+ used_traffic: int
210
+ lifetime_used_traffic: int = 0
211
+ created_at: str
212
+ links: List[str] = []
213
+ subscription_url: str = ""
214
+ excluded_inbounds: Dict[str, List[str]] = {}
215
+ admin: Optional[Admin] = None
216
+
217
+ class SystemStats(BaseModel):
218
+ version: Optional[str] = None
219
+ mem_total: Optional[int] = None
220
+ mem_used: Optional[int] = None
221
+ cpu_cores: Optional[int] = None
222
+ cpu_usage: Optional[float] = None
223
+ total_user: Optional[int] = None
224
+ users_active: Optional[int] = None
225
+ incoming_bandwidth: Optional[int] = None
226
+ outgoing_bandwidth: Optional[int] = None
227
+ incoming_bandwidth_speed: Optional[int] = None
228
+ outgoing_bandwidth_speed: Optional[int] = None
@@ -0,0 +1,53 @@
1
+ Metadata-Version: 2.1
2
+ Name: marzban
3
+ Version: 0.2.9
4
+ Summary: Асинхронная библиотека Python для взаимодействия с MarzbanAPI
5
+ Home-page: https://github.com/sm1ky/marzban_api
6
+ Author: Artem
7
+ Author-email: contant@sm1ky.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.9
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: httpx >=0.23.0
15
+ Requires-Dist: pydantic >=1.10.0
16
+
17
+
18
+ # MarzbanAPI Client
19
+
20
+ **MarzbanAPI Client** is an asynchronous Python library designed for interacting with [Marzban](https://github.com/Gozargah/Marzban). It provides comprehensive methods for managing administrators, users, nodes, and system statistics.
21
+
22
+ ## Installation
23
+
24
+ To install the latest version of the library, use:
25
+
26
+ ```bash
27
+ pip install marzban
28
+ ```
29
+
30
+ ## Project Links
31
+ - **PyPI**: [marzban](https://pypi.org/project/marzban/)
32
+ - **GitHub Repository**: [marzban_api](https://github.com/sm1ky/marzban_api)
33
+
34
+ ## Detailed Documentation
35
+
36
+ For detailed documentation and usage examples, select your preferred language below:
37
+
38
+ - [English](https://github.com/sm1ky/marzban_api/blob/production/.readme/README_en.md)
39
+ - [Русский (Russian)](https://github.com/sm1ky/marzban_api/blob/production/.readme/README_ru.md)
40
+
41
+ ## Contributing
42
+
43
+ We welcome contributions! If you encounter any issues or have suggestions for improvements, please feel free to [open an issue](https://github.com/sm1ky/marzban_api/issues) or submit a Pull Request (PR).
44
+
45
+ ## Support
46
+
47
+ If you have any questions or need assistance, you can contact the author via:
48
+ - **Email**: [contant@sm1ky.com](mailto:contant@sm1ky.com)
49
+ - **Telegram**: [@sm1ky](https://t.me/sm1ky)
50
+
51
+ ## License
52
+
53
+ This project is licensed under the MIT License. For more details, refer to the [LICENSE file](https://github.com/sm1ky/marzban_api/blob/production/LICENSE).
@@ -0,0 +1,8 @@
1
+ marzban/__init__.py,sha256=x797eiZAH7Sr-2_dKKMOqSHbYF42FO410LKliHzTpPs,1302
2
+ marzban/api.py,sha256=Do5W8v8yxMxb5-h6XHKSNM9B2zrCLDcfJIXi4fGmUYs,12474
3
+ marzban/models.py,sha256=cNL3c_bfZKNp0EKuBDfPpO7vAFjQwK2e0VWqHjnJ64c,6931
4
+ marzban-0.2.9.dist-info/LICENSE,sha256=e7OchdHfXoz2OZRHj8iltLIKYwdri9J4_9PMEnov418,1061
5
+ marzban-0.2.9.dist-info/METADATA,sha256=OInLS2XnkrAJVuiLGc5HaT1IVL-GzYRwDot017IgI8s,1952
6
+ marzban-0.2.9.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
7
+ marzban-0.2.9.dist-info/top_level.txt,sha256=KUmBWzTarBlzw2GZOuk-d-jM2GU4zPWo1iwvW_mXS-c,8
8
+ marzban-0.2.9.dist-info/RECORD,,
@@ -1,30 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: marzban
3
- Version: 0.2.7
4
- Summary: Асинхронная библиотека Python для взаимодействия с MarzbanAPI
5
- Home-page: https://github.com/sm1ky/marzban_api
6
- Author: Artem
7
- Author-email: contant@sm1ky.com
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: License :: OSI Approved :: MIT License
10
- Classifier: Operating System :: OS Independent
11
- Requires-Python: >=3.9
12
- Description-Content-Type: text/markdown
13
- License-File: LICENSE
14
- Requires-Dist: httpx >=0.23.0
15
- Requires-Dist: pydantic >=1.10.0
16
-
17
- # MarzbanAPI Client
18
-
19
- Это асинхронная библиотека Python для взаимодействия с MarzbanAPI, предоставляющая методы для управления администраторами, пользователями, узлами и системной статистикой.
20
-
21
- ## Установка
22
-
23
- ```bash
24
- pip install marzban
25
- ```
26
-
27
- Project in Pypi - https://pypi.org/project/marzban/
28
-
29
- If you notice an error, please create a PR and attach logs
30
- You can contact me by mail contant@sm1ky.com or in Telegram @sm1ky
@@ -1,8 +0,0 @@
1
- marzban/__init__.py,sha256=u1L0m8OfCX6zkSaUETHm99keaRs1WxwHMMdwzWiCP4E,1205
2
- marzban/api.py,sha256=30Fx1yzt2rh4BFqlTgP9naIfMW5DXxyOhkhPWFfBrQk,10683
3
- marzban/models.py,sha256=CmmrobcipIsv3m6Jc9XMPdgQMNMoYyJdmwn3NbVIjvU,5600
4
- marzban-0.2.7.dist-info/LICENSE,sha256=e7OchdHfXoz2OZRHj8iltLIKYwdri9J4_9PMEnov418,1061
5
- marzban-0.2.7.dist-info/METADATA,sha256=fnhqkUCqk8jyhetEnlMr2VRWdCry5bUsL7377RVUmZI,1111
6
- marzban-0.2.7.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
7
- marzban-0.2.7.dist-info/top_level.txt,sha256=KUmBWzTarBlzw2GZOuk-d-jM2GU4zPWo1iwvW_mXS-c,8
8
- marzban-0.2.7.dist-info/RECORD,,