sweb-api 0.1.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.
sweb_api-0.1.2/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 zullusa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.4
2
+ Name: sweb-api
3
+ Version: 0.1.2
4
+ Summary: Python client for Sweb.ru API
5
+ Author-email: zullusa <zullusa@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/zullusa/sweb-api
8
+ Project-URL: Repository, https://github.com/zullusa/sweb-api
9
+ Keywords: api,sweb,hosting,vps,domains,json-rpc
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Python: >=3.8
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: requests>=2.28.0
22
+ Requires-Dist: urllib3>=1.26.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
25
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
26
+ Requires-Dist: black>=23.0.0; extra == "dev"
27
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
28
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
29
+ Requires-Dist: types-requests; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # SwebClient - Python клиент для API Sweb.ru
33
+
34
+ Python-клиент для работы с API Sweb.ru через протокол JSON-RPC 2.0.
35
+
36
+ ## Установка
37
+
38
+ ```bash
39
+ pip install sweb-api
40
+ ```
41
+
42
+ ## Быстрый старт
43
+
44
+ ```python
45
+ from sweb_api import SwebClient
46
+
47
+ # Создание клиента с авторизацией
48
+ client = SwebClient("ваш_логин", "ваш_пароль")
49
+
50
+ # Теперь можно использовать доступные методы
51
+ domains = client.domains.index()
52
+ ```
53
+
54
+ ## Конструктор
55
+
56
+ ```python
57
+ SwebClient(login: str, password: str, timeout: int = 30)
58
+ ```
59
+
60
+ Параметры:
61
+ - `login` - логин от личного кабинета Sweb.ru
62
+ - `password` - пароль от личного кабинета Sweb.ru
63
+ - `timeout` - таймаут запросов в секундах (по умолчанию 30)
64
+
65
+ ## Доступные методы
66
+
67
+ ### Виртуальный хостинг
68
+
69
+ | Свойство | Описание | API раздел |
70
+ |----------|----------|------------|
71
+ | `client.domains` | Управление доменами | domains |
72
+ | `client.domains_bonus` | Доменные бонусы | domains/bonus |
73
+ | `client.domains_persons` | Доменные персоны | domains/persons |
74
+ | `client.domains_dns` | Управление DNS | domains/dns |
75
+ | `client.sites` | Управление сайтами | sites |
76
+ | `client.hosting` | Базы данных (MySQL/PostgreSQL) | vh/hosting |
77
+ | `client.backup` | Резервные копии | vh/backup |
78
+ | `client.mail` | Почтовый сервис | vh/mail |
79
+ | `client.ssl` | SSL-сертификаты | vh/ssl |
80
+ | `client.tariff` | Информация о тарифе | tariff |
81
+ | `client.load` | Нагрузка на сервер | vh/load |
82
+ | `client.utils` | SSH-доступ | vh/utils |
83
+ | `client.cron` | Планировщик задач | vh/cron |
84
+ | `client.disk_usage` | Использование диска | vh/utils/diskUsage |
85
+ | `client.ddg` | Защита от DDOS | vh/ddg |
86
+
87
+ ### VPS
88
+
89
+ | Свойство | Описание | API раздел |
90
+ |----------|----------|------------|
91
+ | `client.vps` | Управление VPS | vps |
92
+ | `client.vps_backup` | Резервные копии VPS | vps/backup |
93
+ | `client.vps_ssl` | SSL-сертификаты для VPS | vps/ssl |
94
+ | `client.vps_ip` | Локальная сеть | vps/ip |
95
+ | `client.vps_protected_ip` | Защищённые IP-адреса | vps/protected-ip |
96
+ | `client.vps_dbaas` | DBaaS ( Managed PostgreSQL) | vps/dbaas |
97
+ | `client.vps_balancer` | Балансировщик | vps/balancer |
98
+ | `client.vps_remote_backup` | Облачные бэкапы | vps/remote-backup |
99
+ | `client.vps_monitoring` | Мониторинг | vps/monitoring |
100
+ | `client.vps_monitoring_checks` | Проверки мониторинга | vps/monitoring/checks |
101
+ | `client.vps_monitoring_contacts` | Контакты мониторинга | vps/monitoring/contacts |
102
+
103
+ ### Оплата и финансы
104
+
105
+ | Свойство | Описание | API раздел |
106
+ |----------|----------|------------|
107
+ | `client.pay` | Баланс и платежи | pay |
108
+
109
+ ## Примеры использования
110
+
111
+ ### Получение списка доменов
112
+
113
+ ```python
114
+ from sweb_api import SwebClient
115
+
116
+ client = SwebClient("логин", "пароль")
117
+ domains = client.domains.index()
118
+ print(domains)
119
+ ```
120
+
121
+ ### Информация о тарифе
122
+
123
+ ```python
124
+ client = SwebClient("логин", "пароль")
125
+ tariff_info = client.tariff.serverInfo()
126
+ print(tariff_info)
127
+ ```
128
+
129
+ ### Управление VPS
130
+
131
+ ```python
132
+ client = SwebClient("логин", "пароль")
133
+
134
+ # Получить список VPS
135
+ vps_list = client.vps.index()
136
+
137
+ # Включить VPS
138
+ client.vps.powerOn(vps_id=123)
139
+
140
+ # Выключить VPS
141
+ client.vps.powerOff(vps_id=123)
142
+ ```
143
+
144
+ ### Работа с базами данных
145
+
146
+ ```python
147
+ client = SwebClient("логин", "пароль")
148
+
149
+ # Список баз данных
150
+ databases = client.hosting.databaseGetList()
151
+
152
+ # Создать базу данных
153
+ client.hosting.databaseMysqlCreatedbname="new_db", user="user", password="pass")
154
+ ```
155
+
156
+ ### Работа с почтой
157
+
158
+ ```python
159
+ client = SwebClient("логин", "пароль")
160
+
161
+ # Список почтовых ящиков
162
+ mailboxes = client.mail.getMailboxesList()
163
+
164
+ # Создать почтовый ящик
165
+ client.mail.createMbox(name="info", domain="example.ru", password="secret")
166
+ ```
167
+
168
+ ## Обработка ошибок
169
+
170
+ ```python
171
+ from sweb_api import SwebClient
172
+ from sweb_api.exceptions import AuthenticationError
173
+
174
+ try:
175
+ client = SwebClient("логин", "пароль")
176
+ except AuthenticationError as e:
177
+ print(f"Ошибка авторизации: {e}")
178
+ ```
179
+
180
+ ## Требования
181
+
182
+ - Python 3.8+
183
+ - requests >= 2.28.0
184
+ - urllib3 >= 1.26.0
@@ -0,0 +1,153 @@
1
+ # SwebClient - Python клиент для API Sweb.ru
2
+
3
+ Python-клиент для работы с API Sweb.ru через протокол JSON-RPC 2.0.
4
+
5
+ ## Установка
6
+
7
+ ```bash
8
+ pip install sweb-api
9
+ ```
10
+
11
+ ## Быстрый старт
12
+
13
+ ```python
14
+ from sweb_api import SwebClient
15
+
16
+ # Создание клиента с авторизацией
17
+ client = SwebClient("ваш_логин", "ваш_пароль")
18
+
19
+ # Теперь можно использовать доступные методы
20
+ domains = client.domains.index()
21
+ ```
22
+
23
+ ## Конструктор
24
+
25
+ ```python
26
+ SwebClient(login: str, password: str, timeout: int = 30)
27
+ ```
28
+
29
+ Параметры:
30
+ - `login` - логин от личного кабинета Sweb.ru
31
+ - `password` - пароль от личного кабинета Sweb.ru
32
+ - `timeout` - таймаут запросов в секундах (по умолчанию 30)
33
+
34
+ ## Доступные методы
35
+
36
+ ### Виртуальный хостинг
37
+
38
+ | Свойство | Описание | API раздел |
39
+ |----------|----------|------------|
40
+ | `client.domains` | Управление доменами | domains |
41
+ | `client.domains_bonus` | Доменные бонусы | domains/bonus |
42
+ | `client.domains_persons` | Доменные персоны | domains/persons |
43
+ | `client.domains_dns` | Управление DNS | domains/dns |
44
+ | `client.sites` | Управление сайтами | sites |
45
+ | `client.hosting` | Базы данных (MySQL/PostgreSQL) | vh/hosting |
46
+ | `client.backup` | Резервные копии | vh/backup |
47
+ | `client.mail` | Почтовый сервис | vh/mail |
48
+ | `client.ssl` | SSL-сертификаты | vh/ssl |
49
+ | `client.tariff` | Информация о тарифе | tariff |
50
+ | `client.load` | Нагрузка на сервер | vh/load |
51
+ | `client.utils` | SSH-доступ | vh/utils |
52
+ | `client.cron` | Планировщик задач | vh/cron |
53
+ | `client.disk_usage` | Использование диска | vh/utils/diskUsage |
54
+ | `client.ddg` | Защита от DDOS | vh/ddg |
55
+
56
+ ### VPS
57
+
58
+ | Свойство | Описание | API раздел |
59
+ |----------|----------|------------|
60
+ | `client.vps` | Управление VPS | vps |
61
+ | `client.vps_backup` | Резервные копии VPS | vps/backup |
62
+ | `client.vps_ssl` | SSL-сертификаты для VPS | vps/ssl |
63
+ | `client.vps_ip` | Локальная сеть | vps/ip |
64
+ | `client.vps_protected_ip` | Защищённые IP-адреса | vps/protected-ip |
65
+ | `client.vps_dbaas` | DBaaS ( Managed PostgreSQL) | vps/dbaas |
66
+ | `client.vps_balancer` | Балансировщик | vps/balancer |
67
+ | `client.vps_remote_backup` | Облачные бэкапы | vps/remote-backup |
68
+ | `client.vps_monitoring` | Мониторинг | vps/monitoring |
69
+ | `client.vps_monitoring_checks` | Проверки мониторинга | vps/monitoring/checks |
70
+ | `client.vps_monitoring_contacts` | Контакты мониторинга | vps/monitoring/contacts |
71
+
72
+ ### Оплата и финансы
73
+
74
+ | Свойство | Описание | API раздел |
75
+ |----------|----------|------------|
76
+ | `client.pay` | Баланс и платежи | pay |
77
+
78
+ ## Примеры использования
79
+
80
+ ### Получение списка доменов
81
+
82
+ ```python
83
+ from sweb_api import SwebClient
84
+
85
+ client = SwebClient("логин", "пароль")
86
+ domains = client.domains.index()
87
+ print(domains)
88
+ ```
89
+
90
+ ### Информация о тарифе
91
+
92
+ ```python
93
+ client = SwebClient("логин", "пароль")
94
+ tariff_info = client.tariff.serverInfo()
95
+ print(tariff_info)
96
+ ```
97
+
98
+ ### Управление VPS
99
+
100
+ ```python
101
+ client = SwebClient("логин", "пароль")
102
+
103
+ # Получить список VPS
104
+ vps_list = client.vps.index()
105
+
106
+ # Включить VPS
107
+ client.vps.powerOn(vps_id=123)
108
+
109
+ # Выключить VPS
110
+ client.vps.powerOff(vps_id=123)
111
+ ```
112
+
113
+ ### Работа с базами данных
114
+
115
+ ```python
116
+ client = SwebClient("логин", "пароль")
117
+
118
+ # Список баз данных
119
+ databases = client.hosting.databaseGetList()
120
+
121
+ # Создать базу данных
122
+ client.hosting.databaseMysqlCreatedbname="new_db", user="user", password="pass")
123
+ ```
124
+
125
+ ### Работа с почтой
126
+
127
+ ```python
128
+ client = SwebClient("логин", "пароль")
129
+
130
+ # Список почтовых ящиков
131
+ mailboxes = client.mail.getMailboxesList()
132
+
133
+ # Создать почтовый ящик
134
+ client.mail.createMbox(name="info", domain="example.ru", password="secret")
135
+ ```
136
+
137
+ ## Обработка ошибок
138
+
139
+ ```python
140
+ from sweb_api import SwebClient
141
+ from sweb_api.exceptions import AuthenticationError
142
+
143
+ try:
144
+ client = SwebClient("логин", "пароль")
145
+ except AuthenticationError as e:
146
+ print(f"Ошибка авторизации: {e}")
147
+ ```
148
+
149
+ ## Требования
150
+
151
+ - Python 3.8+
152
+ - requests >= 2.28.0
153
+ - urllib3 >= 1.26.0
@@ -0,0 +1,68 @@
1
+ [build-system]
2
+ requires = ["setuptools>=65.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sweb-api"
7
+ version = "0.1.2"
8
+ description = "Python client for Sweb.ru API"
9
+ readme = "README.md"
10
+ authors = [
11
+ {name = "zullusa", email = "zullusa@gmail.com"}
12
+ ]
13
+ license = "MIT"
14
+ requires-python = ">=3.8"
15
+ classifiers = [
16
+ "Development Status :: 3 - Alpha",
17
+ "Intended Audience :: Developers",
18
+ "Programming Language :: Python :: 3",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ ]
25
+ keywords = ["api", "sweb", "hosting", "vps", "domains", "json-rpc"]
26
+ dependencies = [
27
+ "requests>=2.28.0",
28
+ "urllib3>=1.26.0",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ dev = [
33
+ "pytest>=7.0.0",
34
+ "pytest-cov>=4.0.0",
35
+ "black>=23.0.0",
36
+ "flake8>=6.0.0",
37
+ "mypy>=1.0.0",
38
+ "types-requests",
39
+ ]
40
+
41
+ [project.urls]
42
+ Homepage = "https://github.com/zullusa/sweb-api"
43
+ Repository = "https://github.com/zullusa/sweb-api"
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["."]
47
+ include = ["sweb_api*"]
48
+
49
+ [tool.pytest.ini_options]
50
+ testpaths = ["tests"]
51
+ python_files = "test_*.py"
52
+ python_classes = "Test*"
53
+ python_functions = "test_*"
54
+ addopts = "-v --tb=short"
55
+
56
+ [tool.black]
57
+ line-length = 100
58
+
59
+ [tool.flake8]
60
+ max-line-length = 100
61
+ target-version = ["py310", "py311", "py312", "py313", "py314"]
62
+
63
+ [tool.mypy]
64
+ python_version = "3.10"
65
+ warn_return_any = true
66
+ warn_unused_configs = true
67
+ disallow_untyped_defs = false
68
+ ignore_missing_imports = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,164 @@
1
+ from typing import Any
2
+
3
+ from sweb_api.http.client import JSONRPCClient
4
+ from sweb_api.api.domains import DomainsAPI, DomainsBonusAPI, DomainsPersonsAPI, DomainsDNSAPI
5
+ from sweb_api.api.vh import (
6
+ SitesAPI,
7
+ HostingAPI,
8
+ BackupAPI,
9
+ MailAPI,
10
+ SSLAPI,
11
+ TariffAPI,
12
+ LoadAPI,
13
+ UtilsAPI,
14
+ CronAPI,
15
+ DDGAPI,
16
+ DiskUsageAPI,
17
+ )
18
+ from sweb_api.api.vps import (
19
+ VPSAPI,
20
+ VPSBackupAPI,
21
+ VPSSSLAPI,
22
+ VPSIPAPI,
23
+ VPSProtectedIPAPI,
24
+ VPSDBaaSAPI,
25
+ VPSBalancerAPI,
26
+ VPSRemoteBackupAPI,
27
+ VPSMonitoringAPI,
28
+ VPSMonitoringChecksAPI,
29
+ VPSMonitoringContactsAPI,
30
+ )
31
+ from sweb_api.api.pay import PayAPI
32
+ from sweb_api.exceptions.exceptions import AuthenticationError
33
+
34
+
35
+ class SwebClient:
36
+ BASE_URL = "https://api.sweb.ru"
37
+
38
+ def __init__(self, login: str, password: str, timeout: int = 30):
39
+ self._login = login
40
+ self._password = password
41
+ self._client = JSONRPCClient(self.BASE_URL, timeout)
42
+ self._token = self._authenticate()
43
+ self._client.set_token(self._token)
44
+
45
+ def _authenticate(self) -> Any:
46
+ client = JSONRPCClient(f"{self.BASE_URL}/notAuthorized")
47
+ try:
48
+ params = {"login": self._login, "password": self._password}
49
+ result = client.call("getToken", params) # type: ignore[arg-type]
50
+ if not result or not isinstance(result, str):
51
+ raise AuthenticationError("Invalid token received")
52
+ return result
53
+ except Exception as e:
54
+ if isinstance(e, AuthenticationError):
55
+ raise
56
+ raise AuthenticationError(f"Failed to authenticate: {e}")
57
+
58
+ @property
59
+ def domains(self) -> DomainsAPI:
60
+ return DomainsAPI(self._client, "domains")
61
+
62
+ @property
63
+ def domains_bonus(self) -> DomainsBonusAPI:
64
+ return DomainsBonusAPI(self._client, "domains/bonus")
65
+
66
+ @property
67
+ def domains_persons(self) -> DomainsPersonsAPI:
68
+ return DomainsPersonsAPI(self._client, "domains/persons")
69
+
70
+ @property
71
+ def domains_dns(self) -> DomainsDNSAPI:
72
+ return DomainsDNSAPI(self._client, "domains/dns")
73
+
74
+ @property
75
+ def sites(self) -> SitesAPI:
76
+ return SitesAPI(self._client, "sites")
77
+
78
+ @property
79
+ def hosting(self) -> HostingAPI:
80
+ return HostingAPI(self._client, "vh/hosting")
81
+
82
+ @property
83
+ def backup(self) -> BackupAPI:
84
+ return BackupAPI(self._client, "vh/backup")
85
+
86
+ @property
87
+ def mail(self) -> MailAPI:
88
+ return MailAPI(self._client, "vh/mail")
89
+
90
+ @property
91
+ def ssl(self) -> SSLAPI:
92
+ return SSLAPI(self._client, "vh/ssl")
93
+
94
+ @property
95
+ def tariff(self) -> TariffAPI:
96
+ return TariffAPI(self._client, "tariff")
97
+
98
+ @property
99
+ def load(self) -> LoadAPI:
100
+ return LoadAPI(self._client, "vh/load")
101
+
102
+ @property
103
+ def utils(self) -> UtilsAPI:
104
+ return UtilsAPI(self._client, "vh/utils")
105
+
106
+ @property
107
+ def cron(self) -> CronAPI:
108
+ return CronAPI(self._client, "vh/cron")
109
+
110
+ @property
111
+ def disk_usage(self) -> DiskUsageAPI:
112
+ return DiskUsageAPI(self._client, "vh/utils/diskUsage")
113
+
114
+ @property
115
+ def ddg(self) -> DDGAPI:
116
+ return DDGAPI(self._client, "vh/ddg")
117
+
118
+ @property
119
+ def vps(self) -> VPSAPI:
120
+ return VPSAPI(self._client, "vps")
121
+
122
+ @property
123
+ def vps_backup(self) -> VPSBackupAPI:
124
+ return VPSBackupAPI(self._client, "vps/backup")
125
+
126
+ @property
127
+ def vps_ssl(self) -> VPSSSLAPI:
128
+ return VPSSSLAPI(self._client, "vps/ssl")
129
+
130
+ @property
131
+ def vps_ip(self) -> VPSIPAPI:
132
+ return VPSIPAPI(self._client, "vps/ip")
133
+
134
+ @property
135
+ def vps_protected_ip(self) -> VPSProtectedIPAPI:
136
+ return VPSProtectedIPAPI(self._client, "vps/protected-ip")
137
+
138
+ @property
139
+ def vps_dbaas(self) -> VPSDBaaSAPI:
140
+ return VPSDBaaSAPI(self._client, "vps/dbaas")
141
+
142
+ @property
143
+ def vps_balancer(self) -> VPSBalancerAPI:
144
+ return VPSBalancerAPI(self._client, "vps/balancer")
145
+
146
+ @property
147
+ def vps_remote_backup(self) -> VPSRemoteBackupAPI:
148
+ return VPSRemoteBackupAPI(self._client, "vps/remote-backup")
149
+
150
+ @property
151
+ def vps_monitoring(self) -> VPSMonitoringAPI:
152
+ return VPSMonitoringAPI(self._client, "vps/monitoring")
153
+
154
+ @property
155
+ def vps_monitoring_checks(self) -> VPSMonitoringChecksAPI:
156
+ return VPSMonitoringChecksAPI(self._client, "vps/monitoring/checks")
157
+
158
+ @property
159
+ def vps_monitoring_contacts(self) -> VPSMonitoringContactsAPI:
160
+ return VPSMonitoringContactsAPI(self._client, "vps/monitoring/contacts")
161
+
162
+ @property
163
+ def pay(self) -> PayAPI:
164
+ return PayAPI(self._client, "pay")
File without changes
@@ -0,0 +1,14 @@
1
+ from typing import Any, Optional
2
+ from sweb_api.http.client import JSONRPCClient
3
+
4
+
5
+ class BaseAPI:
6
+ def __init__(self, client: JSONRPCClient, endpoint: str):
7
+ self._client = client
8
+ self._endpoint = endpoint
9
+
10
+ def _call(self, method: str, params: Optional[dict] = None) -> Any:
11
+ return self._client.call(self._endpoint, method, params)
12
+
13
+ def index(self, params: Optional[dict] = None) -> Any:
14
+ return self._call("index", params)