marzban 0.4.0__tar.gz → 0.4.2__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.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: marzban
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Асинхронная библиотека Python для взаимодействия с MarzbanAPI | Поддерживает работу через HTTPS/SSH
5
5
  Home-page: https://github.com/sm1ky/marzban_api
6
6
  Author: Artem
@@ -21,6 +21,16 @@ Requires-Dist: pydantic>=1.10.0
21
21
  Requires-Dist: paramiko>=3.5.0
22
22
  Requires-Dist: sshtunnel>=0.4.0
23
23
  Requires-Dist: datetime>=5.5
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: project-url
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
24
34
 
25
35
 
26
36
  # MarzbanAPI Client
@@ -31,11 +41,12 @@ Requires-Dist: datetime>=5.5
31
41
  [![Supported python versions](https://img.shields.io/pypi/pyversions/marzban.svg)](https://pypi.python.org/pypi/marzban)
32
42
  [![Downloads](https://img.shields.io/pypi/dm/marzban.svg)](https://pypi.python.org/pypi/marzban)
33
43
  [![PyPi Package Version](https://img.shields.io/pypi/v/marzban)](https://pypi.python.org/pypi/marzban)
34
- [![Supported Marzban Version](https://img.shields.io/badge/Marzban-0.8.0-brightgreen)](https://github.com/Gozargah/Marzban)
44
+ [![Supported Marzban Version](https://img.shields.io/github/v/release/Gozargah/Marzban?label=Marzban)](https://github.com/Gozargah/Marzban)
45
+ [![Publish Python Package](https://github.com/sm1ky/marzban_api/actions/workflows/deploy.yml/badge.svg?branch=production)](https://github.com/sm1ky/marzban_api/actions/workflows/deploy.yml)
35
46
 
36
47
 
37
48
  **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.
38
- It supports **Marzban version 0.8.0**, providing comprehensive methods for managing administrators, users, nodes, and system statistics.
49
+ It supports **Marzban version 0.8.4**, providing comprehensive methods for managing administrators, users, nodes, and system statistics.
39
50
 
40
51
  To see the list of supported Marzban versions and corresponding API compatibility, check out our [Supported Versions](https://github.com/sm1ky/marzban_api/blob/production/.readme/supported_version.md) file.
41
52
 
@@ -7,11 +7,12 @@
7
7
  [![Supported python versions](https://img.shields.io/pypi/pyversions/marzban.svg)](https://pypi.python.org/pypi/marzban)
8
8
  [![Downloads](https://img.shields.io/pypi/dm/marzban.svg)](https://pypi.python.org/pypi/marzban)
9
9
  [![PyPi Package Version](https://img.shields.io/pypi/v/marzban)](https://pypi.python.org/pypi/marzban)
10
- [![Supported Marzban Version](https://img.shields.io/badge/Marzban-0.8.0-brightgreen)](https://github.com/Gozargah/Marzban)
10
+ [![Supported Marzban Version](https://img.shields.io/github/v/release/Gozargah/Marzban?label=Marzban)](https://github.com/Gozargah/Marzban)
11
+ [![Publish Python Package](https://github.com/sm1ky/marzban_api/actions/workflows/deploy.yml/badge.svg?branch=production)](https://github.com/sm1ky/marzban_api/actions/workflows/deploy.yml)
11
12
 
12
13
 
13
14
  **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.
14
- It supports **Marzban version 0.8.0**, providing comprehensive methods for managing administrators, users, nodes, and system statistics.
15
+ It supports **Marzban version 0.8.4**, providing comprehensive methods for managing administrators, users, nodes, and system statistics.
15
16
 
16
17
  To see the list of supported Marzban versions and corresponding API compatibility, check out our [Supported Versions](https://github.com/sm1ky/marzban_api/blob/production/.readme/supported_version.md) file.
17
18
 
@@ -46,4 +47,4 @@ If you have any questions or need assistance, you can contact the author via:
46
47
 
47
48
  ## License
48
49
 
49
- 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).
50
+ 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).
@@ -1,4 +1,5 @@
1
1
  from .api import MarzbanAPI
2
+ from .utils import MarzbanTokenCache
2
3
  from .models import (
3
4
  Admin,
4
5
  AdminCreate,
@@ -34,6 +35,7 @@ from .models import (
34
35
  __all__ = (
35
36
  "__version__",
36
37
  "MarzbanAPI",
38
+ "MarzbanTokenCache",
37
39
  "Admin",
38
40
  "AdminCreate",
39
41
  "AdminModify",
@@ -65,4 +67,4 @@ __all__ = (
65
67
  "NextPlanModel"
66
68
  )
67
69
 
68
- __version__ = "0.4.0"
70
+ __version__ = "0.4.2"
@@ -165,6 +165,24 @@ class MarzbanAPI:
165
165
  response = await self._request("GET", url, token, params=params)
166
166
  return [Admin(**admin) for admin in response.json()]
167
167
 
168
+ async def disable_all_users_admin(self, username: str, token: str) -> None:
169
+ url = f"/api/admin/{username}/users/disable"
170
+ await self._request("POST", url, token)
171
+
172
+ async def activate_all_users_admin(self, username: str, token: str) -> None:
173
+ url = f"/api/admin/{username}/users/activate"
174
+ await self._request("POST", url, token)
175
+
176
+ async def reset_admin_usage(self, username: str, token: str) -> Admin:
177
+ url = f"/api/admin/usage/reset/{username}"
178
+ response = await self._request("POST", url, token)
179
+ return Admin(**response.json())
180
+
181
+ async def get_admin_usage(self, username: str, token: str) -> Admin:
182
+ url = f"/api/admin/usage/{username}"
183
+ response = await self._request("GET", url, token)
184
+ return response.json()
185
+
168
186
  async def get_system_stats(self, token: str) -> SystemStats:
169
187
  url = "/api/system"
170
188
  response = await self._request("GET", url, token)
@@ -12,6 +12,7 @@ class Admin(BaseModel):
12
12
  is_sudo: bool
13
13
  telegram_id: Optional[int] = None
14
14
  discord_webhook: Optional[str] = None
15
+ users_usage: Optional[int] = None
15
16
 
16
17
 
17
18
  class AdminCreate(Admin):
@@ -23,6 +24,7 @@ class AdminModify(BaseModel):
23
24
  password: Optional[str] = None
24
25
  telegram_id: Optional[int] = None
25
26
  discord_webhook: Optional[str] = None
27
+ users_usage: Optional[int] = None
26
28
 
27
29
 
28
30
  class HTTPValidationError(BaseModel):
@@ -0,0 +1,35 @@
1
+ import logging
2
+ from datetime import datetime, timedelta
3
+ from typing import Optional
4
+
5
+ from marzban import MarzbanAPI
6
+
7
+
8
+ class MarzbanTokenCache:
9
+ def __init__(self, client: MarzbanAPI,
10
+ username: str, password: str,
11
+ token_expire_minutes: int = 1440):
12
+ self._client = client
13
+ self._username = username
14
+ self._password = password
15
+ self._token_expire_minutes = token_expire_minutes
16
+ self._token: Optional[str] = None
17
+ self._exp_at: Optional[datetime] = None
18
+
19
+ async def get_token(self):
20
+ if not self._exp_at or self._exp_at < datetime.now():
21
+ logging.info(f'Get new token')
22
+ self._token = await self.get_new_token()
23
+ self._exp_at = datetime.now() + timedelta(minutes=self._token_expire_minutes - 1)
24
+ return self._token
25
+
26
+ async def get_new_token(self):
27
+ try:
28
+ token = await self._client.get_token(
29
+ username=self._username,
30
+ password=self._password
31
+ )
32
+ return token.access_token
33
+ except Exception as e:
34
+ logging.error(f'{e}', exc_info=True)
35
+ raise e
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: marzban
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Асинхронная библиотека Python для взаимодействия с MarzbanAPI | Поддерживает работу через HTTPS/SSH
5
5
  Home-page: https://github.com/sm1ky/marzban_api
6
6
  Author: Artem
@@ -21,6 +21,16 @@ Requires-Dist: pydantic>=1.10.0
21
21
  Requires-Dist: paramiko>=3.5.0
22
22
  Requires-Dist: sshtunnel>=0.4.0
23
23
  Requires-Dist: datetime>=5.5
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: project-url
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
24
34
 
25
35
 
26
36
  # MarzbanAPI Client
@@ -31,11 +41,12 @@ Requires-Dist: datetime>=5.5
31
41
  [![Supported python versions](https://img.shields.io/pypi/pyversions/marzban.svg)](https://pypi.python.org/pypi/marzban)
32
42
  [![Downloads](https://img.shields.io/pypi/dm/marzban.svg)](https://pypi.python.org/pypi/marzban)
33
43
  [![PyPi Package Version](https://img.shields.io/pypi/v/marzban)](https://pypi.python.org/pypi/marzban)
34
- [![Supported Marzban Version](https://img.shields.io/badge/Marzban-0.8.0-brightgreen)](https://github.com/Gozargah/Marzban)
44
+ [![Supported Marzban Version](https://img.shields.io/github/v/release/Gozargah/Marzban?label=Marzban)](https://github.com/Gozargah/Marzban)
45
+ [![Publish Python Package](https://github.com/sm1ky/marzban_api/actions/workflows/deploy.yml/badge.svg?branch=production)](https://github.com/sm1ky/marzban_api/actions/workflows/deploy.yml)
35
46
 
36
47
 
37
48
  **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.
38
- It supports **Marzban version 0.8.0**, providing comprehensive methods for managing administrators, users, nodes, and system statistics.
49
+ It supports **Marzban version 0.8.4**, providing comprehensive methods for managing administrators, users, nodes, and system statistics.
39
50
 
40
51
  To see the list of supported Marzban versions and corresponding API compatibility, check out our [Supported Versions](https://github.com/sm1ky/marzban_api/blob/production/.readme/supported_version.md) file.
41
52
 
@@ -4,6 +4,7 @@ setup.py
4
4
  marzban/__init__.py
5
5
  marzban/api.py
6
6
  marzban/models.py
7
+ marzban/utils.py
7
8
  marzban.egg-info/PKG-INFO
8
9
  marzban.egg-info/SOURCES.txt
9
10
  marzban.egg-info/dependency_links.txt
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
5
5
 
6
6
  setup(
7
7
  name="marzban",
8
- version="0.4.0",
8
+ version="0.4.2",
9
9
  packages=find_packages(),
10
10
  install_requires=[
11
11
  "httpx>=0.23.0",
File without changes
File without changes