marzban 0.4.1__py3-none-any.whl → 0.4.2__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
@@ -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.1"
70
+ __version__ = "0.4.2"
marzban/utils.py ADDED
@@ -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
1
  Metadata-Version: 2.2
2
2
  Name: marzban
3
- Version: 0.4.1
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
@@ -41,11 +41,12 @@ Dynamic: summary
41
41
  [![Supported python versions](https://img.shields.io/pypi/pyversions/marzban.svg)](https://pypi.python.org/pypi/marzban)
42
42
  [![Downloads](https://img.shields.io/pypi/dm/marzban.svg)](https://pypi.python.org/pypi/marzban)
43
43
  [![PyPi Package Version](https://img.shields.io/pypi/v/marzban)](https://pypi.python.org/pypi/marzban)
44
- [![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)
45
46
 
46
47
 
47
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.
48
- 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.
49
50
 
50
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.
51
52
 
@@ -0,0 +1,9 @@
1
+ marzban/__init__.py,sha256=jKrQxf2UMpmvvKvt5r6GkHTDF30xZoSO9RJic_ofGwg,1404
2
+ marzban/api.py,sha256=Prk-CyDqBQmztZaWzBmTMa4sewmutsEQiLloA27gXUs,19843
3
+ marzban/models.py,sha256=Mver2ne18efsrT8xHzZjuqhTQr-f6OqJJfziI4V39Us,7754
4
+ marzban/utils.py,sha256=1oweg75j_w2uuZXw96W-ZKn3WiQniqKGqj6PBU6ds74,1174
5
+ marzban-0.4.2.dist-info/LICENSE,sha256=e7OchdHfXoz2OZRHj8iltLIKYwdri9J4_9PMEnov418,1061
6
+ marzban-0.4.2.dist-info/METADATA,sha256=cWLn-DA0Qy5Rp5-rte9l2l2LrBroAJ79X75b3BeHlFs,4082
7
+ marzban-0.4.2.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
8
+ marzban-0.4.2.dist-info/top_level.txt,sha256=KUmBWzTarBlzw2GZOuk-d-jM2GU4zPWo1iwvW_mXS-c,8
9
+ marzban-0.4.2.dist-info/RECORD,,
@@ -1,8 +0,0 @@
1
- marzban/__init__.py,sha256=UT9a6gf12H0h-uxuSb_mkELVusJrxqjCxpxDxIoirkk,1342
2
- marzban/api.py,sha256=Prk-CyDqBQmztZaWzBmTMa4sewmutsEQiLloA27gXUs,19843
3
- marzban/models.py,sha256=Mver2ne18efsrT8xHzZjuqhTQr-f6OqJJfziI4V39Us,7754
4
- marzban-0.4.1.dist-info/LICENSE,sha256=e7OchdHfXoz2OZRHj8iltLIKYwdri9J4_9PMEnov418,1061
5
- marzban-0.4.1.dist-info/METADATA,sha256=OQ3AAFGezmGNVzUiFDAFnku2U0FK1FUYb9fvhnCSgDY,3876
6
- marzban-0.4.1.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
7
- marzban-0.4.1.dist-info/top_level.txt,sha256=KUmBWzTarBlzw2GZOuk-d-jM2GU4zPWo1iwvW_mXS-c,8
8
- marzban-0.4.1.dist-info/RECORD,,